Skip to content

Instantly share code, notes, and snippets.

@aliceh
Last active August 29, 2015 14:05
Show Gist options
  • Save aliceh/87dd54a41c60a0d54500 to your computer and use it in GitHub Desktop.
Save aliceh/87dd54a41c60a0d54500 to your computer and use it in GitHub Desktop.
#!/bin/bash
###################################################################################################################################
# This script installs Motherbrain and Chef-zero on the sane machine and creates ~/.mb/config.json and ~/chef-repo/.chef/knife.rb
# configuration files
#
#
###################################################################################################################################
if rpm -q chefdk; then
echo "Chef DK already installed"
else
echo "Installing Chef DK 0.2.0"
yum install -y https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chefdk-0.2.0-2.el6.x86_64.rpm
fi
if chef gem list motherbrain | grep motherbrain; then
echo "Motherbrain already installed"
else
echo "Installing motherbrain via gem"
echo "This could take a while"
echo
chef gem install motherbrain
fi
if chef gem list chef-zero | grep chef-zero; then
echo "Chef Zero already installed"
else
echo "Installing chef-zero via gem"
echo "This could take a while"
echo
chef gem install chef-zero
fi
echo
echo "Getting the IP address of the deployer machine"
echo
ciab_nic_guess=""
active_nic=""
if [ "$(ifconfig wlan0 | grep 'inet addr')" ]; then
echo "====="
echo "[FATAL] Wireless install not supported!"
echo ""
echo "Your primary network interface appears to be a wireless interface."
echo "Faststart is intended for systems with a fixed ethernet connection and"
echo "a static IP address. Please reconfigure your system."
echo ""
echo "If you want to run a virtual version of Eucalyptus on a laptop,"
echo "consider trying eucadev instead:"
echo ""
echo " https://github.com/eucalyptus/eucadev"
echo ""
curl --silent "https://www.eucalyptus.com/docs/faststart_errors.html?msg=WIRELESS_NOT_SUPPORTED&id=$uuid" >> /tmp/fsout.log
exit 23
elif [ "$(ifconfig em1 | grep 'inet addr')" ]; then
echo "Active network interface em1 found"
ciab_nic_guess="em1"
active_nic="em1"
elif [ "$(ifconfig eth0 | grep 'inet addr')" ]; then
echo "Active network interface eth0 found"
ciab_nic_guess="eth0"
active_nic="eth0"
elif [ "$(ifconfig br0 | grep 'inet addr')" ]; then
# This is a corner case: if br0 is the primary interface,
# it likely means that Eucalyptus has already been
# installed and a bridge established. We still need to determine
# the physical bridhge.
echo "Virtual network interface br0 found"
active_nic="br0"
if [ "$(ifconfig em1)" ]; then
echo "Physical interface em1 found"
ciab_nic_guess="em1"
elif [ "$(ifconfig eth0)" ]; then
echo "Physical interface eth0 found"
ciab_nic_guess="eth0"
else
echo "====="
echo "[WARN] No physical ethernet interface found"
echo ""
echo "No active ethernet interface was found. Please check your network configuration"
echo "and make sure that an ethernet interface is set up as your primary network"
echo "interface, and that it is connected to the internet."
echo ""
echo "It's possible that you're using a non-standard network interface (we expect"
echo "eth0 or em1)."
echo ""
fi
else
echo "====="
echo "[WARN] No active network interface found"
echo ""
echo "No active ethernet interface was found. Please check your network configuration"
echo "and make sure that an ethernet interface is set up as your primary network"
echo "interface, and that it's connected to the internet."
echo ""
echo "It's possible that you're using a non-standard network interface (we expect"
echo "eth0 or em1)."
echo ""
fi
echo "[Precheck] OK, network interfaces checked."
echo ""
ciab_ipaddr_guess=`ifconfig $active_nic | grep "inet addr" | awk '{print $2}' | cut -d':' -f2`
echo "Guessed IP address: $ciab_ipaddr_guess"
read -p "Is $ciab_ipaddr_guess the correct IP address of your machine? <y/N> " prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
then
ipaddr=$ciab_ipaddr_guess
else
read -p "Please enter IP address of your machine:" ipaddr
fi
#######################################
local=/root
echo
echo "Creating ssh keypair for Chef"
echo
mkdir -p $local/chef_ssh
cd $local/chef_ssh
dir="/chef_ssh/chef_key"
ssh-keygen -q -P "" -f chef_key
ssh_key_path=$local$dir
ssh_key_path_escaped="${ssh_key_path//\//\\/}"
echo
cd ..
#######################################
echo
echo "Please supply a username and password for ssh connection to the system under deployment."
echo
read -p "Username:" username
echo "You entered $username"
read -p "Password:" password
echo "You entered $password"
#######################################
echo "Creating a new motherbrain configuration file"
echo
mb_config="config.json"
mkdir -p ~/.mb
cat > ~/.mb/config.json <<EOF
{
"berkshelf": {
"path": "/root/.berkshelf"
},
"chef": {
"api_url": "http://IPADDR:8889",
"api_client": "chef",
"api_key": "SSH_KEY_PATH",
"validator_client": "chef-validator",
"validator_path": "SSH_KEY_PATH",
"bootstrap_proxy": null,
"encrypted_data_bag_secret_path": null
},
"ssh": {
"user": "USERNAME",
"password": "PASSWORD",
"keys": null,
"sudo": true,
"timeout": 10.0,
"verbose": null
},
"winrm": {
"user": "root",
"password": null,
"port": 5985
},
"ssl": {
"verify": true
},
"ridley": {
"connector_pool_size": 25
},
"log": {
"level": "INFO",
"location": "STDOUT"
},
"server": {
"daemonize": false,
"pid": "/var/run/motherbrain/mb.pid"
},
"rest_gateway": {
"enable": false,
"host": "0.0.0.0",
"port": 26100
},
"plugin_manager": {
"eager_loading": false,
"eager_load_interval": 300,
"async_loading": false
},
"ef": {
"api_url": null,
"api_key": null
},
"aws": {
"access_key": null,
"secret_key": null,
"endpoint": null
},
"bootstrap": {
"default_template": null
}
}
EOF
cd $local/.mb/
sed -i "s/IPADDR/$ipaddr/g" $mb_config
sed -i "s/SSH_KEY_PATH/$ssh_key_path_escaped/g" $mb_config
sed -i "s/USERNAME/$username/g" $mb_config
sed -i "s/PASSWORD/$password/g" $mb_config
cd $local
echo
echo "Install git"
echo
yum -y install git
echo "Create directory for chef-repo"
echo
mkdir -p chef-repo
pushd chef-repo
mkdir -p cookbooks
pushd cookbooks
echo "Clone eucalyptus-cookbook and adjust directory structure"
git clone https://github.com/eucalyptus/eucalyptus-cookbook eucalyptus
echo
echo "Creating directory structure"
echo
pushd eucalyptus
berks vendor euca-deps-cookbooks
mv euca-deps-cookbooks/* ..
popd
popd
mkdir -p environments
mkdir -p ~/.chef
dir="/chef-repo/cookbooks"
cookbook_path=$local$dir
cookbook_path_escaped="${cookbook_path//\//\\/}"
chef_config="knife.rb"
echo
echo "Creating knife.rb"
cat > ~/.chef/knife.rb <<EOF
node_name "Deployer"
client_key "SSH_KEY_PATH"
chef_server_url "http://IPADDR:8889"
cookbook_path "COOKBOOK_PATH"
EOF
pushd ~/.chef
sed -i "s/IPADDR/$ipaddr/g" $chef_config
sed -i "s/SSH_KEY_PATH/$ssh_key_path_escaped/g" $chef_config
sed -i "s/COOKBOOK_PATH/$cookbook_path_escaped/g" $chef_config
popd
echo
echo "Uploading cookbooks to Chef-zero"
chef exec '/opt/chefdk/embedded/bin/chef-zero -d -H 0.0.0.0'
knife upload /
echo 'eval "$(chef shell-init bash)"' >> ~/.bashrc
$(chef shell-init bash)
#mb eucalyptus bootstrap <bootstrap_file> -e <environment_name> -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment