Skip to content

Instantly share code, notes, and snippets.

@drewblas
Forked from fnichol/README.md
Created November 14, 2011 15:41
Show Gist options
  • Save drewblas/1364201 to your computer and use it in GitHub Desktop.
Save drewblas/1364201 to your computer and use it in GitHub Desktop.
Chef Bootstrapper For SuSE/SLES

Chef Bootstrapper For SuSE/SLES

Installation

Note: Run this script as the root user (no sudo calls are used in the script).

You will need the curl package installed, though I would have no idea why it wouldn't be installed by default:

zypper --non-interactive install curl

To perform a default prep:

bash <(curl -LB https://gist.github.com/raw/895325/suse_chef_bootstrap.sh)

You can specify an RVM version ([head|latest|x.y.z]):

bash <(curl -LB https://gist.github.com/raw/895325/suse_chef_bootstrap.sh) \
  --rvm-version 1.5.3

You can also override the default ruby (currently ruby-1.9.2-p180):

bash <(curl -LB https://gist.github.com/raw/895325/suse_chef_bootstrap.sh) \
  --rvm-ruby ree-1.8.7-2010.03

What Is Going On

  1. Install package pre-requisites needed for RVM
  2. Install RVM system-wide (gets installed into /usr/local/rvm)
  3. Install package pre-requisites needed to build MRI/REE rubies
  4. Ensure that Sqlite is current and build a version if it is not
  5. Install the RVM ruby and set it as the default
  6. Install the Chef gem
  7. Pull down the Chef cookbook repository from http://github.com/fnichol/chef-repo (gets installed to /var/chef-solo)

The rest is up to you...

#!/usr/bin/env bash
__rvm_pkgs=( sed grep tar gzip bzip2 bash curl git-core )
__mri_pkgs=( gcc-c++ patch zlib zlib-devel libffi-devel sqlite3-devel libxml2-devel libxslt-devel libreadline5 readline-devel libopenssl-devel )
__rvm_ruby_default="ruby-1.9.2-p180"
__cookbooks_path_default="/var/chef-solo"
log() { printf "===> $*\n" ; return $? ; }
fail() { log "\nERROR: $*\n" ; exit 1 ; }
usage() {
printf "
Usage
suse_chef_bootstrap.sh [options] [action]
Options
--rvm-version <head|latest|x.y.z> - Install RVM version [head|latest|x.y.z]
--rvm-ruby <ruby-xxx-pxx|ree-1.8.2-xxx> - Install a specific RVM ruby
Actions
help - Display CLI help (this output)
"
}
install_rvm_prerequisites() {
log "Installing RVM pre-requisite packages..."
zypper --non-interactive install -l "${__rvm_pkgs[@]}"
}
install_mri_prerequisites() {
log "Installing RVM MRI ruby pre-requisite packages..."
zypper --non-interactive install -l "${__mri_pkgs[@]}"
}
install_rvm() {
local flags=""
if [[ -n "$__rvm_version" ]] ; then flags=" --version $__rvm_version" ; fi
if [[ -n "$__rvm_branch" ]] ; then flags=" --branch $__rvm_branch" ; fi
log "Installing RVM..."
bash <(curl -LB "http://rvm.beginrescueend.com/install/rvm") $flags
source /etc/profile.d/rvm.sh
}
install_rvm_ruby() {
if [[ -z "$__rvm_ruby" ]] ; then __rvm_ruby="$__rvm_ruby_default" ; fi
if rvm list strings | grep -q "^ruby-1.9.2-p180" >/dev/null ; then
log "RVM ruby $__rvm_ruby is already installed, so skipping."
else
log "Install RVM ruby ${__rvm_ruby}..."
rvm install $__rvm_ruby
fi
rvm $__rvm_ruby --default
}
compile_sqlite() {
local tar="sqlite-autoconf-3070500.tar.gz"
local dl_dir="/tmp/sqlite-$$"
log "Downloading sqlite3...."
mkdir -p $dl_dir
curl -L "http://www.sqlite.org/$tar" -o "$dl_dir/$tar"
log "Extracting sqlite3..."
(cd $dl_dir && tar -zxf "$dl_dir/$tar")
log "Configuring sqlite3..."
(cd $dl_dir/${tar%.tar.gz} && ./configure)
log "Compiling and installing sqlite3..."
(cd $dl_dir/${tar%.tar.gz} && make && make install)
}
ensure_current_sqlite() {
local current_version=$(sqlite3 --version)
local need_upgrade=1
if [[ $(echo $current_version | cut -d\. -f1) -gt 3 ]] ; then
need_upgrade=0
elif [[ $(echo $current_version | cut -d\. -f1) -eq 3 ]] ; then
if [[ $(echo $current_version | cut -d\. -f2) -gt 6 ]] ; then
need_upgrade=0
elif [[ $(echo $current_version | cut -d\. -f2) -eq 6 ]] ; then
if [[ $(echo $current_version | cut -d\. -f3) -ge 16 ]] ; then
need_upgrade=0
fi
fi
fi
if [[ $need_upgrade -eq 1 ]] ; then
log "Version of sqlite found was too old, so building one..."
compile_sqlite
else
log "Version of sqlite is good."
fi
}
install_chef_gem() {
log "Installing chef gem..."
rvm $__rvm_ruby gem install chef --no-ri --no-rdoc
}
clone_chef_repo() {
if [[ -z "$__cookbooks_path" ]] ; then
__cookbooks_path="$__cookbooks_path_default"
fi
log "Cloning chef repo into $__cookbooks_path..."
mkdir -p $(dirname $__cookbooks_path)
git clone git://github.com/fnichol/chef-repo.git $__cookbooks_path
}
installation_complete() {
printf "
Installation is complete.
"
}
# Parse CLI arguments
while [[ $# -gt 0 ]] ; do
token="$1" ; shift
case "$token" in
--rvm-version)
case "$1" in
*.*.*)
__rvm_version="$1" ; shift
;;
latest|stable)
__rvm_version="latest"
;;
head|master)
__rvm_version="head"
__rvm_branch="master"
;;
*)
fail "--version must be followed by a valid version number x.y.z"
;;
esac
;;
--rvm-ruby)
__rvm_ruby="$1"
;;
help|usage)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
# Perform the actual installation
install_rvm_prerequisites
install_rvm
install_mri_prerequisites
ensure_current_sqlite
install_rvm_ruby
install_chef_gem
clone_chef_repo
installation_complete
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment