Skip to content

Instantly share code, notes, and snippets.

@terrywang
Forked from ryanb/chef_solo_bootstrap.sh
Last active December 14, 2015 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrywang/5070354 to your computer and use it in GitHub Desktop.
Save terrywang/5070354 to your computer and use it in GitHub Desktop.
Chef Solo bootstrap script using rbenv and ruby-build.
#!/bin/bash
# --------------------------------------
#
# Title: Chef Solo Bootstrap
# Author: Terry Wang
# Email: i (at) terry (dot) im
# Homepage: http://terry.im
# File: bootstrap-ubuntu.sh
# Created: Feb, 2013
#
# Purpose: Bootstrap Ruby and Chef on Ubuntu
#
# --------------------------------------
########### Setup Variables #############
RUBY_VERSION="1.9.3-p484"
########### Setup Variables #############
# Keep system up-to-date
sudo apt-get -y update
# Install dependencies
sudo apt-get -y install git build-essential libssl-dev zlib1g-dev \
libreadline6-dev libyaml-dev
# Check if rbenv is already installed
if [ -d ~/.rbenv ]; then
echo "rbenv already installed, remove ~/.rbenv if you want to bootstrap."
exit 1
fi
# Install rbenv and ruby-build
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
# Set up PATH
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile
# Enable shims and autocompletion
echo 'eval "$(rbenv init -)"' >> ~/.profile
# ~/.profile will NOT be read if ~/.bash_profile presents
if [ -f ~/.bash_profile ] || [ -h ~/.bash_profile ]; then
echo "~/.bash_profile found, backing up to ~/.bash_profile.old"
mv ~/.bash_profile{,.old}
fi
# ~/.profile will NOT be read if ~/.bash_login presents
if [ -f ~/.bash_login ] || [ -h ~/.bash_login ]; then
echo "~/.bash_login found, backing up to ~/.bash_login.old"
mv ~/.bash_login{,.old}
fi
# Reload ~/.profile for Ubuntu
source ~/.profile
# Install ruby from source via ruby-build
rbenv install $RUBY_VERSION -v
# Set system wide
rbenv global $RUBY_VERSION
# Skip to avoid issue CHEF-3933
# echo "Updating rubygems..."
# gem update --system
# Install gems
# rbenv-rehash replaces rbenv rehash
gem install rbenv-rehash bundler chef ruby-shadow --no-ri --no-rdoc
# To install berkshelf you need to install libxml2-dev libxslt1-dev
ret=$?
if [ $ret -ne 0 ]; then
echo "Unfortunately something went wrong..." >&2
else
echo "Ready to cook!"
fi
# Restart shell as login shell
exec $SHELL -l
exit 0
@terrywang
Copy link
Author

Forked and modified the bootstrap script to use rbenv with ruby-build to install and manage ruby, install chef. chef-solo is ready for use after the script is run successfully.

It's been tested on Ubuntu 12.10 x86_64, technically should be working on 12.04 x86_64.

Fork if if you want, make it more flexible with versions;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment