#!/bin/env bash # # Cucumber-Chef v<%= Cucumber::Chef::VERSION %> Bootstrap Script # # Generated <%= Time.now.utc %> # set -x export DEBIAN_FRONTEND="noninteractive" CHEF_SOLO_ROOT="/tmp/chef-solo" KNIFE_CONFIG_EXP_FILE="/tmp/knife-config.exp" cd ${CHEF_SOLO_ROOT} grep "<%= @lab_user %>" /etc/sudoers if [ $? -eq 1 ]; then echo "<%= @lab_user %> ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers fi 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 expect mkdir -pv /etc/chef /var/log/chef ${HOME}/.chef cat < EOF wget -v http://www.opscode.com/chef/install.sh bash install.sh -v <%= @chef_version %> <% if (@chef_pre_11 == false) -%> mkdir -pv /var/chef/cache ${CHEF_SOLO_ROOT}/cookbooks/chef-server wget -qO- https://github.com/opscode-cookbooks/chef-server/archive/master.tar.gz | tar xvzC ${CHEF_SOLO_ROOT}/cookbooks/chef-server --strip-components=1 <% else -%> export PATH=/opt/chef/embedded/bin:$PATH cat <' gem 'berkshelf' gem 'moneta', '< 0.7.0' EOF cat < chef-solo --config /etc/chef/solo.rb --json-attributes ${CHEF_SOLO_ROOT}/attributes.json --logfile /var/log/chef/chef-solo.log --log_level debug echo -n "Waiting on <%= File.basename(@chef_validator) %> and <%= File.basename(@chef_webui) %> to appear..." until [ -f <%= @chef_validator %> ] && [ -f <%= @chef_webui %> ]; do echo -n "." sleep 1 done echo "done." cp -v <%= @chef_validator %> <%= @chef_webui %> ~/.chef <% if (@chef_pre_11 == false) -%> ln -sv <%= @chef_validator %> /etc/chef/validation.pem ln -sv <%= @chef_admin %> /etc/chef/admin.pem <% end -%> cat < spawn knife configure -i --server-url https://127.0.0.1 --admin-client-key <%= @chef_admin %> -u ${SUDO_USER} -r '' --defaults --yes -VV <% else -%> spawn knife configure -i --server-url https://127.0.0.1 -u ${SUDO_USER} -r '' --defaults --yes -VV <% end -%> expect "Please enter a password for the new user:" { send "<%= @default_password %>\n" } interact EOF chmod +x ${KNIFE_CONFIG_EXP_FILE} ${KNIFE_CONFIG_EXP_FILE} knife client create <%= @user %> -a -f ${HOME}/.chef/<%= @user %>.pem --disable-editing --yes -VV chown -Rv ${SUDO_USER}:${SUDO_USER} ${HOME}