Bootstrap ubuntu vm. Installs build tools for rails apps, chef (via omnibus), the specified ruby version and a couple of gems.
#!/usr/bin/env bash
# TODO:
#
# * Add support for sudo
# * Add checks for each piece of software to determine if it is already installed
# instead of relying on a single global check of the log file.
#
log_dir=$HOME
log_file=$log_dir/bootstrap-$(date +"%F").log
tmp_dir=/tmp
ruby_version="1.9.3-p194"
if [[ -f $log_file ]] ; then
echo "[bootstrap] INFO: VM has already been bootstrapped" | tee -a $log_file
exit 0
fi
touch $log_file
# verify root user
if [[ $EUID -ne 0 ]]; then
echo "[bootstrap] Must be root user to execute this script" | tee -a $log_file
exit 1
fi
echo "[bootstrap] INFO: Logging output to $log_file" | tee -a $log_file
cd $tmp_dir
echo "[bootstrap] INFO: Installing packages" | tee -a $log_file
apt-get -y update >> $log_file
apt-get -y install \
wget curl build-essential clang \
bison openssl zlib1g \
libxslt1.1 libssl-dev libxslt1-dev \
libxml2 libffi-dev libyaml-dev \
libxslt-dev autoconf libc6-dev \
libreadline6-dev zlib1g-dev libcurl4-openssl-dev \
libtool libsqlite3-0 sqlite3 libsqlite3-dev >> $log_file
apt-get clean >> $log_file
echo "[bootstrap] INFO: Installing chef omnibus" | tee -a $log_file
wget -q https://www.opscode.com/chef/install.sh
bash install.sh >> $log_file
echo "[bootstrap] INFO: Installing ruby-$ruby_version" | tee -a $log_file
wget -q http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-$ruby_version.tar.gz
tar xzf ruby-$ruby_version.tar.gz >> $log_file
cd ruby-$ruby_version && ./configure --prefix=/usr/local >> $log_file \
&& make >> $log_file \
&& make install >> $log_file
cd ..
rm -rf ruby-$ruby_version/
# echo "[testing] INFO: Updating rubygems" | tee -a $log_file
# REALLY_GEM_UPDATE_SYSTEM=yes /usr/local/bin/gem update --system >> $log_file
echo "[bootstrap] INFO: Installing gems" | tee -a $log_file
/usr/local/bin/gem install bundler --no-ri --no-rdoc >> $log_file
/usr/local/bin/gem install rake --force --no-ri --no-rdoc >> $log_file # use --force to overwrite rake binary installed via ruby installer
echo "[bootstrap] INFO: Finished" | tee -a $log_file