Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Forked from fnichol/macosx_bootstrap.sh
Created August 9, 2012 04:55
Show Gist options
  • Save jtimberman/3301140 to your computer and use it in GitHub Desktop.
Save jtimberman/3301140 to your computer and use it in GitHub Desktop.
Mac OS X 10.7/10.8 (Lion/Mountain Lion) Bootstrapping
#!/usr/bin/env bash
set -e
# # Mac OS X 10.7/10.8 (Lion/Mountain Lion) Bootstrapping
#
# ## Pre-requisites
#
# 1. Set your hostname: In **System Preferences** go to **Sharing** and enter
# the name in **Computer Name**
# 2. Run **Software Update** and reboot if necessary
# 3a. For Mountain Lion (10.8): install **Xcode 4.4.1**,
# and **Command Line Tools (Mountain Lion)**
# from https://developer.apple.com/downloads/index.action. Run
# `sudo xcodebuild -license` in **Terminal.app** to agree to EULA
# 3b. For Lion (10.7): install **Xcode 4.1** from
# https://developer.apple.com/downloads/index.action
# 4. Run `java` in **Terminal.app** to force Java to install
#
# ## Running
#
# cd $HOME
# curl -sLO https://raw.github.com/gist/1100372/macosx_bootstrap.sh
# chmod 755 macosx_bootstrap.sh && sudo echo ok
# ./macosx_bootstrap.sh
#
OMNIBUS_ROOT=/opt/opscode
OMNIBUS_URL="http://www.opscode.com/chef/install.sh"
log() { printf -- "-----> $*\n" ; return $? ; }
fail() { printf -- "\nERROR: $*\n" ; exit 1 ; }
prompt_for_client_rb_details() {
printf "\nEnter full node name [ex: bubbles, crank.example.com]\n> "
read NODE_NAME
printf "\nEnter Chef Server URL "
printf "[default: https://api.opscode.com/organizations/YOURORGNAME]\n> "
read SERVER_URL
if [[ -z "$SERVER_URL" ]] ; then
printf "\nEnter Hosted Chef Orgname\n> "
read ORGNAME
SERVER_URL="https://api.opscode.com/organizations/$ORGNAME"
else
ORGNAME="chef"
fi
log "Using Chef Server [${SERVER_URL}]"
}
modify_path() {
log "Modifying PATH for Python/pip installation"
PATH="/usr/local/bin:/usr/local/share/python:$PATH"
export PATH
}
force_sudo() {
log "Attempting to sudo (hopefully last time)"
sudo true
}
create_directories() {
for d in /etc/chef /etc/profile.d /opt ; do
log "Creating directory [${d}]"
sudo mkdir -p $d && sudo chown ${USER} $d
done ; unset d
log "Preparing /usr/local for Homebrew"
sudo mkdir -p /usr/local
sudo chgrp staff /usr/local
sudo chmod g+w /usr/local
}
create_client_rb() {
if [[ -f "/etc/chef/client.rb" ]] ; then
log "File /etc/chef/client.rb already exists, so we will use it"
return 0
fi
log "Creating /etc/chef/client.rb"
prompt_for_client_rb_details
cat <<CLIENT_RB > /etc/chef/client.rb
log_level :info
log_location STDOUT
chef_server_url '$SERVER_URL'
validation_client_name '${ORGNAME}-validator'
node_name '$NODE_NAME'
base_dir = "#{ENV['HOME']}/.chef"
# Paths
checksum_path "#{base_dir}/checksum"
file_cache_path "#{base_dir}/cache"
file_backup_path "#{base_dir}/backup"
cache_options({:path => "#{base_dir}/cache/checksums", :skip_expires => true})
CLIENT_RB
chmod 644 /etc/chef/client.rb
}
create_validation_pem() {
if [[ -f "/etc/chef/validation.pem" ]] ; then
log "File /etc/chef/validation.pem already exists, so we will use it"
return 0
fi
log "Creating /etc/chef/validation.pem key [$KEY]"
printf "\nPaste in the validation.pem file contents, followed by one blank line\n> "
while read line ; do
if [[ -z "$line" ]] ; then
break
else
echo "$line" >> /etc/chef/validation.pem
fi
done ; unset line
chmod 0600 /etc/chef/validation.pem
}
install_chef() {
if [[ -f $OMNIBUS_ROOT/bin/chef-client ]] ; then
log "Omnibus Chef installation detected, skipping install"
return 0
fi
local minor_version="$(sw_vers \
| awk '/^ProductVersion:/ { print $2 }' \
| awk -F'.' '{ print $2 }')"
log "Downloading and installing Omnibus Chef"
if [ $minor_version -eq 8 ] ; then
curl -L $OMNIBUS_URL \
| sed 's/^\( "10.7") platform_version="10.7.2" ;;\)/\1@ "10.8") platform_version="10.7.2" ;;/' \
| tr '@' '\n' \
| sudo bash
else
curl -L $OMNIBUS_URL | sudo bash
fi
}
install_chef_gems() {
local omnibus_gem_cmd="$OMNIBUS_ROOT/embedded/bin/gem"
local system_gem_cmd="/usr/bin/gem"
for g in rvm homesick ; do
for gem_cmd in $omnibus_gem_cmd $system_gem_cmd ; do
if $gem_cmd list --no-versions | grep -q "^$g$" >/dev/null ; then
log "Gem [$g] installed with $gem_cmd, skipping."
else
log "Installing gem [$g] with $gem_cmd"
sudo $gem_cmd install $g --no-ri --no-rdoc
fi
done ; unset gem_cmd
done ; unset g
}
run_chef_client() {
log "Executing chef-client run"
mkdir -p $HOME/.chef/logs
time (chef-client | tee -a $HOME/.chef/logs/chef-client.log)
}
force_sudo
modify_path
create_directories
install_chef
install_chef_gems
create_client_rb
create_validation_pem
run_chef_client
log "Bootstrap complete."
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment