Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 199 lines (176 sloc) 6.941 kb
f80e5d0 @joshfng Adding the shell script
authored
1 #!/bin/bash
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
authored
2 #
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
authored
3 # Rails Ready
4 #
1327485 @joshfng Add email to source
authored
5 # Author: Josh Frye <joshfng@gmail.com>
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
authored
6 # Licence: MIT
7 #
8 # Contributions from: Wayne E. Seguin <wayneeseguin@gmail.com>
eae4f60 @joshfng Listing Ryan McGeary as a contributor
authored
9 # Contributions from: Ryan McGeary <ryan@mcgeary.org>
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
authored
10 #
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
authored
11 shopt -s nocaseglob
12 set -e
f80e5d0 @joshfng Adding the shell script
authored
13
a5b1406 @joshfng Ruby 1.9.3-p0
authored
14 ruby_version="1.9.3"
e2e2afb @joshfng Update to p125
authored
15 ruby_version_string="1.9.3-p125"
16 ruby_source_url="http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz"
17 ruby_source_tar_name="ruby-1.9.3-p125.tar.gz"
18 ruby_source_dir_name="ruby-1.9.3-p125"
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
19 script_runner=$(whoami)
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
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...
authored
22
fd5b5e1 @joshfng Better redirection of stdout and stderr. Added signal trapping for ctrl-...
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-...
authored
29 # trap keyboard interrupt (control-c)
30 trap control_c SIGINT
31
d79902e @joshfng Clear term window before displaying rails ready script.
authored
32 clear
33
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
34 echo "#################################"
35 echo "########## Rails Ready ##########"
36 echo "#################################"
37
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
authored
38 #determine the distro
f2f9c9c @joshfng Fix syntax error.
authored
39 if [[ $MACHTYPE = *linux* ]] ; then
3addbfe @joshfng Only cat /etc/issue if running Linux.
authored
40 distro_sig=$(cat /etc/issue)
f3ea8e7 @joshfng Initial OSX support. Install Homebrew, imagemagick, and an updated git.
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.
authored
46 elif [[ $MACHTYPE = *darwin* ]] ; then
f3ea8e7 @joshfng Initial OSX support. Install Homebrew, imagemagick, and an updated git.
authored
47 distro="osx"
d1ab83f @joshfng Check for gcc on osx. Fixes #24
authored
48 if [[ ! -f $(which gcc) ]]; then
77c7a0a @joshfng Pull scripts from master branch.
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.
authored
50 exit 1
56687f4 @joshfng Revert "Merge pull request #18 from larzconwell/master" due to failing t...
authored
51 fi
f2f9c9c @joshfng Fix syntax error.
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.
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...
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
authored
66
445e9d1 @joshfng Redirect output without trucating install log. Add some info the the ter...
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.
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 :)
authored
82 # Ask if you want to build Ruby or install RVM
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
83 echo -e "\n"
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
authored
84 echo "Build Ruby or install RVM?"
84bcee2 @joshfng Fix typo. Closes #12
authored
85 echo "=> 1. Build from source"
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
86 echo "=> 2. Install RVM"
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
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...
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 :)
authored
92 elif [ $whichRuby -eq 2 ] ; then
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
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 :)
authored
94 else
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
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 :)
authored
96 exit 1
97 fi
98
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
99 echo -e "\n=> Creating install dir..."
f80e5d0 @joshfng Adding the shell script
authored
100 cd && mkdir -p railsready/src && cd railsready && touch install.log
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
101 echo "==> done..."
f80e5d0 @joshfng Adding the shell script
authored
102
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
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.
authored
105 if [[ $MACHTYPE = *linux* ]] ; then
56687f4 @joshfng Revert "Merge pull request #18 from larzconwell/master" due to failing t...
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.
authored
107 else
56687f4 @joshfng Revert "Merge pull request #18 from larzconwell/master" due to failing t...
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.
authored
109 fi
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
authored
110 echo -e "\n==> done running $distro specific commands..."
f80e5d0 @joshfng Adding the shell script
authored
111
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
authored
112 #now that all the distro specific packages are installed lets get Ruby
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
authored
113 if [ $whichRuby -eq 1 ] ; then
114 # Install Ruby
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
115 echo -e "\n=> Downloading Ruby $ruby_version_string \n"
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
authored
116 cd $railsready_path/src && wget $ruby_source_url
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
117 echo -e "\n==> done..."
d2cb2cb @joshfng These can use the ruby_version_string variable also.
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...
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...
authored
125 echo "==> done..."
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
authored
126 elif [ $whichRuby -eq 2 ] ; then
127 #thanks wayneeseguin :)
eb23e8f @joshfng Adding more output redirection.
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
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-...
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...
authored
134 #if RVM is installed as user root it goes to /usr/local/rvm/ not ~/.rvm
5206441 @joshfng Check for .bashrc and .bash_profile before attempting to insert rvm func...
authored
135 if [ -f ~/.bashrc ] ; then
136 echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*' >> "$HOME/.bashrc"
137 fi
138 if [ -f ~/.bash_profile ] ; then
139 echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*' >> "$HOME/.bash_profile"
140 fi
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
authored
141 echo "==> done..."
142 echo "=> Loading RVM..."
504f941 @joshfng Make sure file exists before trying to source them.
authored
143 if [ -f ~/.bashrc ] ; then
144 source ~/.bashrc
145 fi
146 if [ -f ~/.bash_profile ] ; then
147 source ~/.bash_profile
148 fi
2fbfcd2 @joshfng More file checks.
authored
149 if [ -f ~/.rvm/scripts/rvm ] ; then
150 source ~/.rvm/scripts/rvm
151 fi
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
152 echo "==> done..."
d11b5fe @leocassarani Fix repeated typo in console output
leocassarani authored
153 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...
authored
154 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
155 rvm install $ruby_version >> $log_file 2>&1
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
156 echo -e "\n==> done..."
ac30de2 @joshfng Use ruby_version variable.
authored
157 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...
authored
158 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
159 rvm --default use $ruby_version >> $log_file 2>&1
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
160 echo "==> done..."
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
authored
161 else
162 echo "How did you even get here?"
163 exit 1
164 fi
f80e5d0 @joshfng Adding the shell script
authored
165
166 # Reload bash
9333ab2 @joshfng Added distro detection, "recipe" system, and CentOS 5.5 support.
authored
167 echo -e "\n=> Reloading shell so ruby and rubygems are available..."
2fbfcd2 @joshfng More file checks.
authored
168 if [ -f ~/.bashrc ] ; then
169 source ~/.bashrc
170 fi
171 if [ -f ~/.bash_profile ] ; then
172 source ~/.bash_profile
173 fi
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
174 echo "==> done..."
f80e5d0 @joshfng Adding the shell script
authored
175
a8bb1d5 @joshfng Dealing with the RVM .bashrc and .bash_profile issues. Changing RVM inst...
authored
176 echo -e "\n=> Updating Rubygems..."
177 if [ $whichRuby -eq 1 ] ; then
178 sudo gem update --system --no-ri --no-rdoc >> $log_file 2>&1
179 elif [ $whichRuby -eq 2 ] ; then
180 gem update --system --no-ri --no-rdoc >> $log_file 2>&1
181 fi
182 echo "==> done..."
183
184 echo -e "\n=> Installing Bundler, Passenger and Rails..."
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
authored
185 if [ $whichRuby -eq 1 ] ; then
f1d425d @rmm5t DRY'd up the log file handling and added a $log_file variable
rmm5t authored
186 sudo gem install bundler passenger rails --no-ri --no-rdoc >> $log_file 2>&1
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
authored
187 elif [ $whichRuby -eq 2 ] ; then
f1d425d @rmm5t DRY'd up the log file handling and added a $log_file variable
rmm5t authored
188 gem install bundler passenger rails --no-ri --no-rdoc >> $log_file 2>&1
1e2bfbb @joshfng Install from source or install RVM. Thanks wayneeseguin :)
authored
189 fi
76b2b58 @joshfng Set variables for use within script. Dramatically improve the formatting...
authored
190 echo "==> done..."
f80e5d0 @joshfng Adding the shell script
authored
191
fd5b5e1 @joshfng Better redirection of stdout and stderr. Added signal trapping for ctrl-...
authored
192 echo -e "\n#################################"
193 echo "### Installation is complete! ###"
194 echo -e "#################################\n"
f80e5d0 @joshfng Adding the shell script
authored
195
d595f2b @joshfng RVM handles .bashrc and .bash_profile functions correctly now. Closes #1...
authored
196 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...
authored
197
198 echo -e "\n Thanks!\n-Josh\n"
Something went wrong with that request. Please try again.