forked from bobanj/railsready
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrailsready.sh
176 lines (152 loc) · 5.9 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
#!/bin/bash
#
# Author: Josh Frye <joshfng@gmail.com>
# Licence: MIT
#
# Contributions from: Wayne E. Seguin <wayneeseguin@gmail.com>
# Contributions from: Ryan McGeary <ryan@mcgeary.org>
#
ruby_version="1.9.2"
ruby_version_string="1.9.2p180"
ruby_source_url="ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p180.tar.gz"
ruby_source_tar_name="ruby-1.9.2-p180.tar.gz"
ruby_source_dir_name="ruby-1.9.2-p180"
script_runner=$(whoami)
postgresql_version="9.0"
log_file=$(cd && pwd)/railsready/install.log
control_c()
{
echo -en "\n\n*** Exiting ***\n\n"
exit 1
}
# trap keyboard interrupt (control-c)
trap control_c SIGINT
shopt -s extglob
set -e
# Check if the user has sudo privileges.
sudo -v >/dev/null 2>&1 || { echo $script_runner has no sudo privileges ; exit 1; }
echo -e "\n\n"
echo "#################################"
echo "########## Rails Ready ##########"
echo "#################################"
echo -e "\n\n"
echo "!!! This script will update your system! Run on a fresh install only !!!"
echo "run tail -f $log_file in a new terminal to watch the install"
echo -e "\n"
echo "What this script gets you:"
echo " * An updated system"
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"
# Ask if you want to build Ruby or install RVM
echo -e "\n"
echo "Build Ruby or install RVM?"
echo "=> 1. Build from souce"
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..."
# Update the system before going any further
echo -e "\n=> Updating system (this may take awhile)..."
sudo apt-get update >> $log_file 2>&1 \
&& sudo apt-get -y upgrade >> $log_file 2>&1
echo "==> done..."
# Install build tools
echo -e "\n=> Installing build tools..."
sudo apt-get -y install \
wget curl build-essential \
bison 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 >> $log_file 2>&1
echo "==> done..."
echo -e "\n=> Installing libs needed for sqlite and mysql..."
sudo apt-get -y install libsqlite3-0 sqlite3 libsqlite3-dev libmysqlclient16-dev libmysqlclient16 >> $log_file 2>&1
echo -e "\n=> Installing libs needed for postgresql..."
sudo apt-get -y install libpq-dev>> $log_file 2>&1
echo "==> done..."
# Install imagemagick
echo -e "\n=> Installing imagemagick (this may take awhile)..."
sudo apt-get -y install imagemagick libmagick9-dev >> $log_file 2>&1
echo "==> done..."
# Install git-core
echo -e "\n=> Installing git..."
sudo apt-get -y install git-core >> $log_file 2>&1
echo "==> done..."
if [ $whichRuby -eq 1 ] ; then
# Install Ruby
echo -e "\n=> Downloading Ruby $ruby_version_string \n"
cd 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 awhile)..."
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 http://rvm.beginrescueend.com/releases/rvm-install-head
chmod +x rvm-install-head
"$PWD/rvm-install-head" >> $log_file 2>&1
[[ -f rvm-install-head ]] && rm -f rvm-install-head
echo -e "\n=> Setting up RVM to load with new shells..."
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*' >> "$HOME/.bashrc"
echo "==>done..."
echo "=> Loading RVM..."
#if RVM is installed as user root it goes to /usr/local/rvm/ not ~/.rvm
if [ $script_runner != "root" ] ; then
source ~/.rvm/scripts/rvm
source ~/.bashrc
fi
echo "==> done..."
echo -e "\n=> Installing $ruby_version_string (this will take awhile)..."
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 1.9.2 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 bashrc so ruby and rubygems are available..."
source ~/.bashrc
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=> Installing Postgresql, Postfix..."
sudo apt-get -y install postgresql-$postgresql_version >> $log_file 2>&1
# sudo apt-get -y install postfix >> $log_file 2>&1
echo "==> done..."
echo -e "\n#################################"
echo "### Installation is complete! ###"
echo -e "#################################\n"
echo -e "\n !!! logout and back in to access Ruby or run source ~/.bashrc !!!\n"
echo -e "\n Thanks!\n-Josh\n"