#!/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 %> apt-get -y --force-yes update apt-get -y --force-yes install build-essential wget http://www.opscode.com/chef/install.sh bash install.sh -v <%= @chef_version %> rpm -Uvh --nodeps /tmp/*rpm export PATH=/opt/chef/embedded/bin/:$PATH mkdir -p /etc/chef/ mkdir -p /var/log/chef/ cat < /etc/chef/solo.rb file_cache_path "/tmp/chef-solo/" cookbook_path %w(/tmp/chef-solo/cookbooks/ /tmp/chef-solo/site-cookbooks/) role_path "/tmp/chef-solo/roles/" EOF cat < /etc/chef/bootstrap.json <%= @chef_client_attributes.to_json %> EOF cd /tmp/chef-solo/ gem install bundler --no-ri --no-rdoc bundle install --standalone --path vendor/bundle --binstubs bin/librarian-chef install chef-solo --config /etc/chef/solo.rb --json-attributes /etc/chef/bootstrap.json --logfile /var/log/chef/chef-solo.log --log_level debug 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 -Rv ${SUDO_USER}:${SUDO_USER} ${HOME} touch ${CUCUMBER_CHEF_BOOTSTRAP_DONE}