bash -c ' CUCUMBER_CHEF_BOOTSTRAP_DONE="/.cucumber-chef-bootstrap-finished" [ -f ${CUCUMBER_CHEF_BOOTSTRAP_DONE} ] && echo "Already bootstrapped!" && exit export DEBIAN_FRONTEND=noninteractive sed -i "s/127.0.0.1 localhost/127.0.0.1 <%= @config[:hostname] %> <%= @config[:hostname].split(".")[0] %> localhost/" /etc/hosts echo "<%= @config[:hostname] %>" | tee /etc/hostname hostname <%= @config[:hostname] %> 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 chown -R ${SUDO_USER}:${SUDO_USER} ${HOME}/.gnupg apt-get -q -y upgrade cat <:4000 chef-solr chef-solr/amqp_password password <%= @config[:amqp_password] %> chef-server-webui chef-server-webui/admin_password password <%= @config[:admin_password] %> EOF apt-get -q -y install chef chef-server 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 <%= @config[:user] %> -d -a -f ${HOME}/.chef/<%= @config[: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 <%= @config[:attributes].to_json %> EOF touch ${CUCUMBER_CHEF_BOOTSTRAP_DONE} '