Skip to content

Instantly share code, notes, and snippets.

@TylerRick
Created March 2, 2012 21:49
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save TylerRick/1961638 to your computer and use it in GitHub Desktop.
Save TylerRick/1961638 to your computer and use it in GitHub Desktop.
Bootstrap script for chef-solo that installs rvm, ruby, bundler, and chef (within a gemset)
#!/bin/bash
# Actual filename: bootstrap/rvm.erb
# vim: set ft=sh
# This script automatically bootstraps the system with everything it needs to run chef-solo.
# Note: This should only do the absolute minimum necessary to get chef-solo (and your recipes)
# working. All else should be done via chef recipes.
#===================================================================================================
# Config
# Note: This can be configured in .chef/knife.rb
ruby_version="<%= Chef::Config[:rvm_ruby_version] || 'ruby-1.9.3' %>"
#===================================================================================================
# Initialization
<%
# Find your local Gemfile. It may not always be at ./Gemfile, so we use this helper
require 'bundler'
gemfile = Bundler::SharedHelpers.default_gemfile
#p Chef::Config.inspect
#puts gemfile.read
%>
#root='/etc/chef'
root="$HOME/chef"
if [ -f /etc/lsb-release ]; then
. /etc/lsb-release
OS=$DISTRIB_ID
elif [ -f /etc/redhat-release ]; then
OS="Red Hat"
else
echo "This distro isn't supported yet. Please submit a patch."
ls /etc/*release
cat /etc/issue
exit 1
fi
function fail {
echo "Error: $1"
exit 1
}
#===================================================================================================
echo
echo "Installing prerequisite packages..."
if [[ "$OS" == "Ubuntu" ]]; then
sudo apt-get update
# This list is from running 'rvm requirements'
sudo apt-get install -y build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
elif [[ "$OS" == "Red Hat" ]]; then
sudo yum install -y git gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison
#iconv-devel # For centos >= 5.4 iconv-devel is provided by glibc
# Another option for installing git would be:
# sudo bash < <( curl -s https://rvm.beginrescueend.com/install/git )
fi
#===================================================================================================
# In case rvm is already installed, this is needed in order to find the rvm command.
source /etc/profile
if { rvm -v; }; then
echo "rvm already installed"
else
echo "Installing rvm..."
sudo bash -s stable < <(curl --silent https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
source /etc/profile
fi
#===================================================================================================
echo
echo "Adding $(whoami) to rvm group..."
#sudo adduser $(whoami) rvm
sudo usermod -a -G rvm $(whoami)
id --groups --name | grep rvm || fail "$(whoami) still not in rvm group; you may have to run this again for the new group to take effect"
echo
echo "Installing ruby..."
rvm install $ruby_version || fail "rvm install $ruby_version failed"
rvm --default $ruby_version
mkdir -p ${root}
cd ${root}
#===================================================================================================
echo "Creating ${root}/.rvmrc..."
cat <<End > .rvmrc
rvm use --create default@chef
End
rvm rvmrc trust .
#===================================================================================================
echo
echo "Installing default gems..."
rvm use default@global &&
rvm default@global do gem install bundler --no-rdoc --no-ri || fail "could not install bundler"
rvm use --create default@chef &&
gem install chef --no-rdoc --no-ri || fail "could not install chef"
#===================================================================================================
echo
echo "Creating ${root}/Gemfile..."
cat <<End > Gemfile
<%= gemfile.read %>
End
echo
echo "Installing gems needed by the user's chef recipes (running bundle install)..."
# Note: If this fails with permissions issues, make sure you have g+w permissions: sudo chmod g+w -R /usr/local/rvm/gems
bundle install | grep -v '^Using'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment