#!/bin/env bash # # Cucumber-Chef Bootstrap Script # # Generated <%= Time.now.utc %> # set -x CUCUMBER_CHEF_BOOTSTRAP_DONE="/.cucumber-chef-bootstrap-finished" [ -f ${CUCUMBER_CHEF_BOOTSTRAP_DONE} ] && echo "Already bootstrapped!" && exit export DEBIAN_FRONTEND=noninteractive echo "127.0.0.1 <%= @hostname_full %> <%= @hostname_short %>" | tee -a /etc/hosts echo "<%= @hostname_full %>" | tee /etc/hostname hostname <%= @hostname_full %> echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | tee /etc/apt/sources.list.d/opscode.list mkdir -p /etc/apt/trusted.gpg.d gpg --fetch-key http://apt.opscode.com/packages@opscode.com.gpg.key gpg --export packages@opscode.com | tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null apt-get -q -y --force-yes update apt-get -q -y --force-yes -o Dpkg::Options::="--force-confnew" install opscode-keyring apt-get -q -y --force-yes update chown -R ${SUDO_USER}:${SUDO_USER} ${HOME}/.gnupg apt-get -q -y upgrade cat <:4000 chef-solr chef-solr/amqp_password password <%= @amqp_password %> chef-server-webui chef-server-webui/admin_password password <%= @admin_password %> EOF CHEF_VERSION=`apt-cache showpkg chef | tee | grep -m 1 "<%= @chef_version %>" | cut -c -<%= @chef_version.length + 3 %>` CHEF_SERVER_VERSION=`apt-cache showpkg chef-server | tee | grep -m 1 "<%= @chef_version %>" | cut -c -<%= @chef_version.length + 3 %>` apt-get -q -y --force-yes install chef=$CHEF_VERSION chef-server=$CHEF_SERVER_VERSION echo -n "Waiting on validation.pem and webui.pem to appear..." until [ -f /etc/chef/validation.pem ] && [ -f /etc/chef/webui.pem ]; do echo -n "." sleep 1 done echo "done." mkdir -p ~/.chef cp /etc/chef/validation.pem /etc/chef/webui.pem ~/.chef apt-get -q -y install expect KNIFE_CONFIG_EXP_FILE="/tmp/knife-config.exp" cat < ${KNIFE_CONFIG_EXP_FILE} #!/usr/bin/expect -f set timeout 10 spawn knife configure -i expect "Overwrite ${HOME}/.chef/knife.rb" { send "Y\n" } expect "Where should I put the config file?" { send "\n" } expect "Please enter the chef server URL" { send "\n" } expect "Please enter a clientname for the new client" { send "${SUDO_USER}\n" } expect "Please enter the existing admin clientname" { send "\n" } expect "Please enter the location of the existing admin client" { send "${HOME}/.chef/webui.pem\n" } expect "Please enter the validation clientname" { send "\n" } expect "Please enter the location of the validation key" { send "${HOME}/.chef/validation.pem\n" } expect "Please enter the path to a chef repository" { send "${HOME}/chef_repo\n" } interact EOF chmod +x ${KNIFE_CONFIG_EXP_FILE} ${KNIFE_CONFIG_EXP_FILE} knife client create <%= @user %> -d -a -f ${HOME}/.chef/<%= @user %>.pem chown -R ${SUDO_USER}:${SUDO_USER} ${HOME} nc -w 1 127.0.0.1 4040 if [ $? -ne 0 ]; then /etc/init.d/chef-server-webui stop && sleep 3 /usr/sbin/chef-server-webui -e production & while true; do nc -w 1 127.0.0.1 4040 if [ $? -eq 0 ]; then break fi sleep 1 done kill `jobs -p` && sleep 3 /etc/init.d/chef-server-webui start && sleep 3 fi if [ ! -f /etc/chef/client.pem ]; then /etc/init.d/chef-client restart echo -n "Waiting on client.pem to appear..." i="0" until [ -f /etc/chef/client.pem ]; do i=$[$i+1] sleep 1 echo -n "." if [ $i -gt 60 ]; then echo -n "restart-chef-client" /etc/init.d/chef-client restart i="0" fi done echo "done." fi cat < /etc/chef/first-boot.json <%= @chef_client_attributes.to_json %> EOF touch ${CUCUMBER_CHEF_BOOTSTRAP_DONE}