Skip to content

Instantly share code, notes, and snippets.

@letronje
Created June 27, 2012 14:01
Show Gist options
  • Save letronje/3004234 to your computer and use it in GitHub Desktop.
Save letronje/3004234 to your computer and use it in GitHub Desktop.
#!/bin/bash
cd /usr/local/bin/
echo "Listing location of gem and ruby, Press enter to proceed"
which gem
which ruby
read
sudo mv gem gem1.5.2
sudo mv ruby ruby1.8.7
sudo ln -snf /usr/local/bin/gem1.5.2 /usr/local/bin/gem
sudo ln -snf /usr/local/bin/ruby1.8.7 /usr/local/bin/ruby
ls -l /usr/local/bin/gem
ls -l /usr/local/bin/ruby
sudo apt-get -y install \
wget curl build-essential \
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
sudo apt-get -y install \
libsqlite3-0 sqlite3 \
libsqlite3-dev libmysqlclient-dev
sudo apt-get -y install \
imagemagick libmagick9-dev
shopt -s nocaseglob
set -e
ruby_version="1.9.3"
ruby_version_string="1.9.3-p194"
ruby_source_url="http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz"
ruby_source_tar_name="ruby-1.9.3-p194.tar.gz"
ruby_source_dir_name="ruby-1.9.3-p194"
script_runner=$(whoami)
railsready_path=$(cd && pwd)/railsready
log_file="$railsready_path/install.log"
control_c()
{
echo -en "\n\n*** Exiting ***\n\n"
exit 1
}
# trap keyboard interrupt (control-c)
trap control_c SIGINT
clear
echo "#################################"
echo "########## Rails Ready ##########"
echo "#################################"
#determine the distro
if [[ $MACHTYPE = *linux* ]] ; then
distro_sig=$(cat /etc/issue)
if [[ $distro_sig =~ ubuntu ]] ; then
distro="ubuntu"
elif [[ $distro_sig =~ centos ]] ; then
distro="centos"
fi
elif [[ $MACHTYPE = *darwin* ]] ; then
distro="osx"
if [[ ! -f $(which gcc) ]]; then
echo -e "\nXCode/GCC must be installed in order to build required software. Note that XCode does not automatically do this, but you may have to go to the Preferences menu and install command line tools manually.\n"
exit 1
fi
else
echo -e "\nRails Ready currently only supports Ubuntu and CentOS and OSX\n"
exit 1
fi
#now check if user is root
if [ $script_runner == "root" ] ; then
echo -e "\nThis script must be run as a normal user with sudo privileges\n"
exit 1
fi
# Check if the user has sudo privileges.
#sudo -v >/dev/null 2>&1 || { echo $script_runner has no sudo privileges ; exit 1; }
# Ask if you want to build Ruby or install RVM
echo -e "\n"
echo "Build Ruby or install RVM?"
echo "=> 1. Build from source"
echo "=> 2. Install RVM"
echo -n "Select your Ruby type [1 or 2]? "
read whichRuby
if [ $whichRuby -eq 1 ] ; then
echo -e "\n\n!!! Set to build Ruby from source and install system wide !!! \n"
elif [ $whichRuby -eq 2 ] ; then
echo -e "\n\n!!! Set to install RVM for user: $script_runner !!! \n"
else
echo -e "\n\n!!! Must choose to build Ruby or install RVM, exiting !!!"
exit 1
fi
echo -e "\n=> Creating install dir..."
cd && mkdir -p railsready/src && cd railsready && touch install.log
echo "==> done..."
if [ $whichRuby -eq 1 ] ; then
# Install Ruby
echo -e "\n=> Downloading Ruby $ruby_version_string \n"
cd $railsready_path/src && wget $ruby_source_url
echo -e "\n==> done..."
echo -e "\n=> Extracting Ruby $ruby_version_string"
tar -xzf $ruby_source_tar_name >> $log_file 2>&1
echo "==> done..."
echo -e "\n=> Building Ruby $ruby_version_string (this will take a while)..."
cd $ruby_source_dir_name && ./configure --prefix=/usr/local >> $log_file 2>&1 \
&& make >> $log_file 2>&1 \
&& sudo make install >> $log_file 2>&1
echo "==> done..."
elif [ $whichRuby -eq 2 ] ; then
#thanks wayneeseguin :)
echo -e "\n=> Installing RVM the Ruby enVironment Manager http://rvm.beginrescueend.com/rvm/install/ \n"
curl -O -L -k https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer
chmod +x rvm-installer
"$PWD/rvm-installer" >> $log_file 2>&1
[[ -f rvm-installer ]] && rm -f rvm-installer
echo -e "\n=> Setting up RVM to load with new shells..."
#if RVM is installed as user root it goes to /usr/local/rvm/ not ~/.rvm
if [ -f ~/.bashrc ] ; then
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*' >> "$HOME/.bashrc"
fi
if [ -f ~/.bash_profile ] ; then
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*' >> "$HOME/.bash_profile"
fi
echo "==> done..."
echo "=> Loading RVM..."
if [ -f ~/.bashrc ] ; then
source ~/.bashrc
fi
if [ -f ~/.bash_profile ] ; then
source ~/.bash_profile
fi
if [ -f ~/.rvm/scripts/rvm ] ; then
source ~/.rvm/scripts/rvm
fi
echo "==> done..."
echo -e "\n=> Installing Ruby $ruby_version_string (this will take a while)..."
echo -e "=> More information about installing rubies can be found at http://rvm.beginrescueend.com/rubies/installing/ \n"
rvm install $ruby_version >> $log_file 2>&1
echo -e "\n==> done..."
echo -e "\n=> Using $ruby_version and setting it as default for new shells..."
echo "=> More information about Rubies can be found at http://rvm.beginrescueend.com/rubies/default/"
rvm --default use $ruby_version >> $log_file 2>&1
echo "==> done..."
else
echo "How did you even get here?"
exit 1
fi
# Reload bash
echo -e "\n=> Reloading shell so ruby and rubygems are available..."
if [ -f ~/.bashrc ] ; then
source ~/.bashrc
fi
if [ -f ~/.bash_profile ] ; then
source ~/.bash_profile
fi
echo "==> done..."
cd /usr/local/bin/
sudo mv ruby ruby1.9.3
sudo ln -snf /usr/local/bin/ruby1.9.3 /usr/local/bin/ruby
ls -l /usr/local/bin/gem
ls -l /usr/local/bin/ruby
sudo gem update --system --no-ri --no-rdoc
sudo gem install bundler --no-ri --no-rdoc
sudo gem install rails -v 3.0.9 --no-ri --no-rdoc
sudo gem install whenever --no-ri --no-rdoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment