Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env bash
#
# Supported Operating Systems:
#
# - Arch Linux
# - RedHat Based (CentOS, ...)
# - Debian Based (Ubuntu, ...)
#
if [[ ! "root" = "$(whoami)" ]] ; then
echo -e "This script must be run as root." && exit 1
fi ; clear
#
# Configuration Options
#
rvm_release_url="http://rvm.beginrescueend.com/releases/"
rvm_repo_url="git://github.com/wayneeseguin/rvm.git"
rvm_install_location="/usr/local/rvm"
# Set the version below in order to deploy a specific release version of rvm.
#
#version="0.0.91"
#
# Setup system PATH
# - Ensure that /usr/local/bin is in the path
#
PATH=$(echo "/usr/local/bin:$PATH" | tr -s ':' '\n' | awk '!($0 in a){a[$0];print}' | tr -s '\n' ':' | sed 's#:$##')
#echo "export PATH=$PATH" >> /etc/profile
#
# System packages required for building rubies.
#
echo -e "Installing System packages required for building rubies."
rvm_apt_get_binary="$(which aptitude 2> /dev/null)"
rvm_pacman_binary="$(which pacman 2> /dev/null)"
rvm_yum_binary="$(which yum 2> /dev/null)"
#
# Debian based systems
#
if [[ ! -z "$rvm_apt_get_binary" ]] ; then
aptitude install -y build-essential libreadline5-dev libssl-dev bison libz-dev zlib1g zlib1g-dev libxml2 libxml2-dev libxslt-dev libssl-dev openssl git readline-devel
#
# Arch Linux based system
#
elif [[ ! -z "$rvm_pacman_binary" ]] ; then
pacman -S --noconfirm gcc gcc-libs make kernel-headers zlib libtool bison gdb strace gettext openssl git readline-devel
#
# RedHat based system
#
elif [[ ! -z "$rvm_yum_binary" ]] ; then
yum install -y gcc gcc-c++ kernel-devel zlib libtool bison gdb strace gettext git rpm-build redhat-rpm-config zlib-devel openssl openssl-devel readline-devel
fi
#
# Configure system level gem settings.
#
echo -e "Disabling ri & rdoc for gem installations."
echo "gem: --no-rdoc --no-ri" >> /etc/gemrc
#
# Install rvm at the system level.
#
cd /tmp && rm -rf /tmp/rvm
if [[ ! -z "$version" ]] ; then
echo -e "Installing rvm $version giting and installing rvm\n\n"
curl -O $rvm_release_url/rvm-$version.tar.gz && tar zxf rvm-$version.tar.gz && cd rvm-$version && ./install && cd ../ && rm -rf ./rvm
else
echo -e "Installing rvm $version from github repository head.\n\n"
cd ~ && git clone --depth 1 $rvm_repo_url temp_rvm && cd temp_rvm && ./install && cd ~ && rm -rf temp_rvm
fi
rm -rf /tmp/rvm # Cleanup, aisle 3
#
# rvm system level configuration.
#
rm /etc/rvmrc
echo "rvm_path=/usr/local/rvm" > /etc/rvmrc
#
# rvm profile.d entry
#
mkdir -p /etc/profile.d
rm /etc/profile.d/rvm.sh
cat <<-File > /etc/profile.d/rvm.sh
# Load RVM if it is installed,
# first try to load user install
# then try to load root install, if user install is not there.
if [ -s "$HOME/.rvm/scripts/rvm" ] ; then
source "$HOME/.rvm/scripts/rvm"
elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then
source "/usr/local/rvm/scripts/rvm"
fi
File
echo -ne "\nWould you like us to make a group called rvm which can be used to manage rvm? (EXPERMENTAL) [yes/NO] "
read response
if [[ "yes" = "$response" ]] ; then
groupadd rvm
chown -R root:rvm /usr/local/rvm
chmod -R g+w /usr/local/rvm
echo -e "\nJust add any users to the rvm group, and they should be able to manage all of the system rubies"
fi
cat<<-Message
rvm has been installed into /usr/local/rvm
You can install rubies with the following commands:
rvm install 1.8.6
rvm install 1.8.7
rvm install ree
rvm install 1.9.1
You can then set the default system wide ruby using
rvm use <version> --default
Message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment