-
Notifications
You must be signed in to change notification settings - Fork 0
/
railsready.sh
196 lines (174 loc) · 6.8 KB
/
railsready.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
#
# Rails Ready
#
# Author: Josh Frye <[email protected]>
# Licence: MIT
#
# Contributions from: Wayne E. Seguin <[email protected]>
# Contributions from: Ryan McGeary <[email protected]>
#
shopt -s nocaseglob
set -e
ruby_version="1.9.3"
ruby_version_string="1.9.3-p327"
ruby_source_url="http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz"
ruby_source_tar_name="ruby-1.9.3-p327.tar.gz"
ruby_source_dir_name="ruby-1.9.3-p327"
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, 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
echo -e "\n\n"
echo "run tail -f $log_file in a new terminal to watch the install"
echo -e "\n"
echo "What this script gets you:"
echo " * Ruby $ruby_version_string"
echo " * Imagemagick"
echo " * libs needed to run Rails (sqlite, mysql, etc)"
echo " * Bundler, Passenger, and Rails gems"
echo " * Git"
echo -e "\nThis script is always changing."
echo "Make sure you got it from https://github.com/joshfng/railsready"
# 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..."
echo -e "\n=> Downloading and running recipe for $distro...\n"
#Download the distro specific recipe and run it, passing along all the variables as args
if [[ $MACHTYPE = *linux* ]] ; then
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
else
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
fi
echo -e "\n==> done running $distro specific commands..."
#now that all the distro specific packages are installed lets get Ruby
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..."
echo -e "\n=> Updating Rubygems..."
if [ $whichRuby -eq 1 ] ; then
sudo gem update --system --no-ri --no-rdoc >> $log_file 2>&1
elif [ $whichRuby -eq 2 ] ; then
gem update --system --no-ri --no-rdoc >> $log_file 2>&1
fi
echo "==> done..."
echo -e "\n=> Installing Bundler, Passenger and Rails..."
if [ $whichRuby -eq 1 ] ; then
sudo gem install bundler passenger rails --no-ri --no-rdoc >> $log_file 2>&1
elif [ $whichRuby -eq 2 ] ; then
gem install bundler passenger rails --no-ri --no-rdoc >> $log_file 2>&1
fi
echo "==> done..."
echo -e "\n#################################"
echo "### Installation is complete! ###"
echo -e "#################################\n"
echo -e "\n !!! logout and back in to access Ruby !!!\n"
echo -e "\n Thanks!\n-Josh\n"