Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 194 lines (171 sloc) 6.744 kb
f80e5d0 @joshfng Adding the shell script
joshfng authored
1 #!/bin/bash
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
2 #
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
joshfng authored
3 # Rails Ready
4 #
1327485 @joshfng Add email to source
joshfng authored
5 # Author: Josh Frye <joshfng@gmail.com>
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
6 # Licence: MIT
7 #
8 # Contributions from: Wayne E. Seguin <wayneeseguin@gmail.com>
eae4f60 @joshfng Listing Ryan McGeary as a contributor
joshfng authored
9 # Contributions from: Ryan McGeary <ryan@mcgeary.org>
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
10 #
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
joshfng authored
11 shopt -s nocaseglob
12 set -e
f80e5d0 @joshfng Adding the shell script
joshfng authored
13
a5b1406 @joshfng Ruby 1.9.3-p0
joshfng authored
14 ruby_version="1.9.3"
15 ruby_version_string="1.9.3-p0"
16 ruby_source_url="http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz"
17 ruby_source_tar_name="ruby-1.9.3-p0.tar.gz"
18 ruby_source_dir_name="ruby-1.9.3-p0"
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
19 script_runner=$(whoami)
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
joshfng authored
20 railsready_path=$(cd && pwd)/railsready
21 log_file="$railsready_path/install.log"
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
22
fd5b5e1 @joshfng Better redirection of stdout and stderr. Added signal trapping for ctrl-...
joshfng authored
23 control_c()
24 {
25 echo -en "\n\n*** Exiting ***\n\n"
26 exit 1
27 }
f1d425d @rmm5t DRY'd up the log file handling and added a $log_file variable
rmm5t authored
28
fd5b5e1 @joshfng Better redirection of stdout and stderr. Added signal trapping for ctrl-...
joshfng authored
29 # trap keyboard interrupt (control-c)
30 trap control_c SIGINT
31
d79902e @joshfng Clear term window before displaying rails ready script.
joshfng authored
32 clear
33
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
34 echo "#################################"
35 echo "########## Rails Ready ##########"
36 echo "#################################"
37
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
joshfng authored
38 #determine the distro
f2f9c9c @joshfng Fix syntax error.
joshfng authored
39 if [[ $MACHTYPE = *linux* ]] ; then
3addbfe @joshfng Only cat /etc/issue if running Linux.
joshfng authored
40 distro_sig=$(cat /etc/issue)
f3ea8e7 @joshfng Initial OSX support. Install Homebrew, imagemagick, and an updated git.
joshfng authored
41 if [[ $distro_sig =~ ubuntu ]] ; then
42 distro="ubuntu"
43 elif [[ $distro_sig =~ centos ]] ; then
44 distro="centos"
45 fi
f2f9c9c @joshfng Fix syntax error.
joshfng authored
46 elif [[ $MACHTYPE = *darwin* ]] ; then
f3ea8e7 @joshfng Initial OSX support. Install Homebrew, imagemagick, and an updated git.
joshfng authored
47 distro="osx"
f2f9c9c @joshfng Fix syntax error.
joshfng authored
48 if [[ ! -s /Library/Developer/Shared/XcodeTools.plist ]] ; then
77c7a0a @joshfng Pull scripts from master branch.
joshfng authored
49 echo -e "\nXCode must be installed in order to build required software.\n"
f3ea8e7 @joshfng Initial OSX support. Install Homebrew, imagemagick, and an updated git.
joshfng authored
50 exit 1
56687f4 @joshfng Revert "Merge pull request #18 from larzconwell/master" due to failing t...
joshfng authored
51 fi
f2f9c9c @joshfng Fix syntax error.
joshfng authored
52 else
53 echo -e "\nRails Ready currently only supports Ubuntu and CentOS and OSX\n"
54 exit 1
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
joshfng authored
55 fi
56
57 #now check if user is root
58 if [ $script_runner == "root" ] ; then
59 echo -e "\nThis script must be run as a normal user with sudo privileges\n"
60 exit 1
61 fi
62
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
63 echo -e "\n\n"
64 echo "!!! This script will update your system! Run on a fresh install only !!!"
f1d425d @rmm5t DRY'd up the log file handling and added a $log_file variable
rmm5t authored
65 echo "run tail -f $log_file in a new terminal to watch the install"
f80e5d0 @joshfng Adding the shell script
joshfng authored
66
445e9d1 @joshfng Redirect output without trucating install log. Add some info the the ter...
joshfng authored
67 echo -e "\n"
68 echo "What this script gets you:"
69 echo " * An updated system"
70 echo " * Ruby $ruby_version_string"
71 echo " * Imagemagick"
72 echo " * libs needed to run Rails (sqlite, mysql, etc)"
73 echo " * Bundler, Passenger, and Rails gems"
74 echo " * Git"
75
76 echo -e "\nThis script is always changing."
77 echo "Make sure you got it from https://github.com/joshfng/railsready"
78
e5ec94d @joshfng Perform sudo check after explaining what the script does.
joshfng authored
79 # Check if the user has sudo privileges.
80 sudo -v >/dev/null 2>&1 || { echo $script_runner has no sudo privileges ; exit 1; }
81
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
82 # Ask if you want to build Ruby or install RVM
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
83 echo -e "\n"
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
84 echo "Build Ruby or install RVM?"
84bcee2 @joshfng Fix typo. Closes #12
joshfng authored
85 echo "=> 1. Build from source"
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
86 echo "=> 2. Install RVM"
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
87 echo -n "Select your Ruby type [1 or 2]? "
88 read whichRuby
89
90 if [ $whichRuby -eq 1 ] ; then
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
91 echo -e "\n\n!!! Set to build Ruby from source and install system wide !!! \n"
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
92 elif [ $whichRuby -eq 2 ] ; then
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
93 echo -e "\n\n!!! Set to install RVM for user: $script_runner !!! \n"
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
94 else
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
95 echo -e "\n\n!!! Must choose to build Ruby or install RVM, exiting !!!"
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
96 exit 1
97 fi
98
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
99 echo -e "\n=> Creating install dir..."
f80e5d0 @joshfng Adding the shell script
joshfng authored
100 cd && mkdir -p railsready/src && cd railsready && touch install.log
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
101 echo "==> done..."
f80e5d0 @joshfng Adding the shell script
joshfng authored
102
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
joshfng authored
103 echo -e "\n=> Downloading and running recipe for $distro...\n"
104 #Download the distro specific recipe and run it, passing along all the variables as args
d1f00c5 @joshfng Run curl if osx.
joshfng authored
105 if [[ $MACHTYPE = *linux* ]] ; then
56687f4 @joshfng Revert "Merge pull request #18 from larzconwell/master" due to failing t...
joshfng authored
106 wget --no-check-certificate -O $railsready_path/src/$distro.sh https://raw.github.com/joshfng/railsready/master/recipes/$distro.sh && cd $railsready_path/src && bash $distro.sh $ruby_version $ruby_version_string $ruby_source_url $ruby_source_tar_name $ruby_source_dir_name $whichRuby $railsready_path $log_file
d1f00c5 @joshfng Run curl if osx.
joshfng authored
107 else
56687f4 @joshfng Revert "Merge pull request #18 from larzconwell/master" due to failing t...
joshfng authored
108 cd $railsready_path/src && curl -O https://raw.github.com/joshfng/railsready/master/recipes/$distro.sh && bash $distro.sh $ruby_version $ruby_version_string $ruby_source_url $ruby_source_tar_name $ruby_source_dir_name $whichRuby $railsready_path $log_file
d1f00c5 @joshfng Run curl if osx.
joshfng authored
109 fi
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
joshfng authored
110 echo -e "\n==> done running $distro specific commands..."
f80e5d0 @joshfng Adding the shell script
joshfng authored
111
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
joshfng authored
112 #now that all the distro specific packages are installed lets get Ruby
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
113 if [ $whichRuby -eq 1 ] ; then
114 # Install Ruby
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
115 echo -e "\n=> Downloading Ruby $ruby_version_string \n"
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
joshfng authored
116 cd $railsready_path/src && wget $ruby_source_url
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
117 echo -e "\n==> done..."
d2cb2cb @joshfng These can use the ruby_version_string variable also.
joshfng authored
118 echo -e "\n=> Extracting Ruby $ruby_version_string"
f1d425d @rmm5t DRY'd up the log file handling and added a $log_file variable
rmm5t authored
119 tar -xzf $ruby_source_tar_name >> $log_file 2>&1
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
120 echo "==> done..."
d11b5fe @leocassarani Fix repeated typo in console output
leocassarani authored
121 echo -e "\n=> Building Ruby $ruby_version_string (this will take a while)..."
f1d425d @rmm5t DRY'd up the log file handling and added a $log_file variable
rmm5t authored
122 cd $ruby_source_dir_name && ./configure --prefix=/usr/local >> $log_file 2>&1 \
123 && make >> $log_file 2>&1 \
124 && sudo make install >> $log_file 2>&1
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
125 echo "==> done..."
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
126 elif [ $whichRuby -eq 2 ] ; then
127 #thanks wayneeseguin :)
eb23e8f @joshfng Adding more output redirection.
joshfng authored
128 echo -e "\n=> Installing RVM the Ruby enVironment Manager http://rvm.beginrescueend.com/rvm/install/ \n"
e3d9b6e @joshfng Use correct RVM installer script. Fixes #14
joshfng authored
129 curl -O -L -k https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer
130 chmod +x rvm-installer
131 "$PWD/rvm-installer" >> $log_file 2>&1
132 [[ -f rvm-installer ]] && rm -f rvm-installer
fd5b5e1 @joshfng Better redirection of stdout and stderr. Added signal trapping for ctrl-...
joshfng authored
133 echo -e "\n=> Setting up RVM to load with new shells..."
0e4e14a @joshfng Don't try to source ~/.rvm if root. RVM installs to other location as ro...
joshfng authored
134 #if RVM is installed as user root it goes to /usr/local/rvm/ not ~/.rvm
d595f2b @joshfng RVM handles .bashrc and .bash_profile functions correctly now. Closes #1...
joshfng authored
135 echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*' >> "$HOME/.bash_profile"
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
joshfng authored
136 echo "==> done..."
137 echo "=> Loading RVM..."
504f941 @joshfng Make sure file exists before trying to source them.
joshfng authored
138 if [ -f ~/.bashrc ] ; then
139 source ~/.bashrc
140 fi
141 if [ -f ~/.bash_profile ] ; then
142 source ~/.bash_profile
143 fi
2fbfcd2 @joshfng More file checks.
joshfng authored
144 if [ -f ~/.rvm/scripts/rvm ] ; then
145 source ~/.rvm/scripts/rvm
146 fi
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
147 echo "==> done..."
d11b5fe @leocassarani Fix repeated typo in console output
leocassarani authored
148 echo -e "\n=> Installing Ruby $ruby_version_string (this will take a while)..."
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
149 echo -e "=> More information about installing rubies can be found at http://rvm.beginrescueend.com/rubies/installing/ \n"
f1d425d @rmm5t DRY'd up the log file handling and added a $log_file variable
rmm5t authored
150 rvm install $ruby_version >> $log_file 2>&1
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
151 echo -e "\n==> done..."
ac30de2 @joshfng Use ruby_version variable.
joshfng authored
152 echo -e "\n=> Using $ruby_version and setting it as default for new shells..."
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
153 echo "=> More information about Rubies can be found at http://rvm.beginrescueend.com/rubies/default/"
f1d425d @rmm5t DRY'd up the log file handling and added a $log_file variable
rmm5t authored
154 rvm --default use $ruby_version >> $log_file 2>&1
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
155 echo "==> done..."
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
156 else
157 echo "How did you even get here?"
158 exit 1
159 fi
f80e5d0 @joshfng Adding the shell script
joshfng authored
160
161 # Reload bash
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
joshfng authored
162 echo -e "\n=> Reloading shell so ruby and rubygems are available..."
2fbfcd2 @joshfng More file checks.
joshfng authored
163 if [ -f ~/.bashrc ] ; then
164 source ~/.bashrc
165 fi
166 if [ -f ~/.bash_profile ] ; then
167 source ~/.bash_profile
168 fi
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
169 echo "==> done..."
f80e5d0 @joshfng Adding the shell script
joshfng authored
170
a8bb1d5 @joshfng Dealing with the RVM .bashrc and .bash_profile issues. Changing RVM inst...
joshfng authored
171 echo -e "\n=> Updating Rubygems..."
172 if [ $whichRuby -eq 1 ] ; then
173 sudo gem update --system --no-ri --no-rdoc >> $log_file 2>&1
174 elif [ $whichRuby -eq 2 ] ; then
175 gem update --system --no-ri --no-rdoc >> $log_file 2>&1
176 fi
177 echo "==> done..."
178
179 echo -e "\n=> Installing Bundler, Passenger and Rails..."
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
180 if [ $whichRuby -eq 1 ] ; then
f1d425d @rmm5t DRY'd up the log file handling and added a $log_file variable
rmm5t authored
181 sudo gem install bundler passenger rails --no-ri --no-rdoc >> $log_file 2>&1
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
182 elif [ $whichRuby -eq 2 ] ; then
f1d425d @rmm5t DRY'd up the log file handling and added a $log_file variable
rmm5t authored
183 gem install bundler passenger rails --no-ri --no-rdoc >> $log_file 2>&1
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
joshfng authored
184 fi
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
joshfng authored
185 echo "==> done..."
f80e5d0 @joshfng Adding the shell script
joshfng authored
186
fd5b5e1 @joshfng Better redirection of stdout and stderr. Added signal trapping for ctrl-...
joshfng authored
187 echo -e "\n#################################"
188 echo "### Installation is complete! ###"
189 echo -e "#################################\n"
f80e5d0 @joshfng Adding the shell script
joshfng authored
190
d595f2b @joshfng RVM handles .bashrc and .bash_profile functions correctly now. Closes #1...
joshfng authored
191 echo -e "\n !!! logout and back in to access Ruby !!!\n"
445e9d1 @joshfng Redirect output without trucating install log. Add some info the the ter...
joshfng authored
192
193 echo -e "\n Thanks!\n-Josh\n"
Something went wrong with that request. Please try again.