forked from doubtfire-lms/doubtfire-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·288 lines (245 loc) · 6.69 KB
/
setup.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
#
# Detects if system is macOS
#
is_mac() {
if [[ `uname` == "Darwin" ]]; then
return 0
else
return 1
fi
}
#
# Detects if system is Linux
#
is_linux() {
if [[ `uname` == "Linux" ]]; then
return 0
else
return 1
fi
}
#
# Detects if environment is ZSH
#
is_zsh() {
if [ -n "$ZSH_VERSION" ]; then
return 0
elif [ -n "$BASH_VERSION" ]; then
return 1
fi
}
#
# Resets the color
#
msg_reset () {
RESET='\033[0m'
printf "${RESET}\n"
}
#
# Log an error
#
error () {
RED_FORE='\033[0;31m'
printf "${RED_FORE}ERROR: $1"
msg_reset
}
#
# Log verbose message
#
verbose () {
CYAN_FORE='\033[0;36m'
printf "${CYAN_FORE}INFO: $1"
msg_reset
}
#
# Log message
#
msg () {
printf "$1\n"
}
#
# Install Homebrew
#
install_homebrew () {
command -v brew >/dev/null 2>&1 || {
msg "Installing Homebrew..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap caskroom/cask
if [ $? -ne 0 ]; then
error "Was not able to install Homebrew."
exit 1
fi
}
}
#
# Install Ruby envioronment for linux
#
install_rbenv_linux() {
msg "Installing Ruby..."
sudo apt update
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
sudo apt-get install -y libreadline-dev
verbose "Git repos cloned"
if [ -n "$ZSH_VERSION" ]; then
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
elif [ -n "$BASH_VERSION" ]; then
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
fi
}
#
# Install rbenv and ruby-build
#
install_rbenv () {
msg "Installing Ruby-build and rbenv..."
command -v rbenv >/dev/null 2>&1 || {
if is_mac;
then
brew install ruby ruby-build rbenv
else
install_rbenv_linux
fi
if [ -n "$ZSH_VERSION" ]; then
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
elif [ -n "$BASH_VERSION" ]; then
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
fi
verbose "Installed rbenv"
}
RUBY_VERSION=$(cat .ruby-version)
msg "Installing Ruby $RUBY_VERSION, this will take a few minutes..."
CONFIGURE_OPTS="--disable-install-doc --enable-shared" rbenv install $RUBY_VERSION
if [ $? -ne 0 ]; then
error "Was not able to install rbenv, or rbenv was already Installed, will continue with installation."
fi
verbose "Installed Ruby-build and rbenv"
eval "$(rbenv init -)"
rbenv rehash
}
#
# Install postgres
#
install_postgres () {
msg "Installing Postgres..."
if is_mac;
then
brew cask install postgres --appdir=/Applications
export PATH=/Applications/Postgres.app/Contents/Versions/*/bin:$PATH
verbose "Installed Postgres, should now be on path"
if [ $? -ne 0 ]; then
error "Could not install postgres."
fi
verbose "Installed postgres"
else
sudo apt-get install -y postgresql \
postgresql-contrib \
libpq-dev
msg "Ensure pg_config is on the PATH, and then login to Postgres. You will need to locate where `apt-get` has Installed your Postgres binary and add this to your PATH. You can use: whereis psql for that, but ensure you add the directory and not the executable to the path"
read -p "Press enter to continue"
export PATH=/usr/bin:$PATH
sudo -u postgres createuser --superuser $USER
sudo -u postgres createdb $USER
fi
psql -c "DO \$body\$ BEGIN IF NOT EXISTS (SELECT * FROM pg_catalog.pg_user WHERE usename = 'itig') THEN CREATE ROLE itig WITH CREATEDB PASSWORD 'd872\$dh' LOGIN; END IF; END \$body\$;"
if [ $? -ne 0 ]; then
error "Could not install postgres. Please ensure psql is on the path, and then rerun this script."
exit 1
fi
verbose "Installed Postgres"
}
#
# Install native tools
#
install_native_tools () {
msg "Installing native tools..."
if is_mac; then
brew install imagemagick@6 libmagic ghostscript ffmpeg
brew link --force imagemagick@6
msg "Trying to install pygments with easy_install, please enter your password"
sudo easy_install Pygments
else
sudo apt-get install -y ghostscript \
imagemagick \
libmagickwand-dev \
libmagic-dev \
python-pygments \
ffmpeg
fi
if [ $? -ne 0 ]; then
error "Could not install native tools, please review the terminal window for details."
error "Packages may have already been Installed, attempting to continue with setup."
else
verbose "Installed native tools"
fi
}
#
# Install Doubtfire gem dependencies
#
install_dfire_dependencies () {
msg "Installing Doubtfire dependencies..."
gem install bundler
bundler install --without production staging
rbenv rehash
source ~/.bashrc
msg "Populating database"
rake db:create
rake db:populate
if [ $? -ne 0 ]; then
error "Could not populate database."
exit 1
fi
verbose "populated database"
}
#
# Install Overcommit and DSTIL hooks.
#
install_dstil_overcommit () {
msg "Installing DSTIL hooks..."
curl -s https://raw.githubusercontent.com/dstil/dotfiles/master/bootstrap | bash
gem install overcommit
rbenv rehash
overcommit --install
dstil --sign
verbose "Installed DSTIL hooks."
}
#
# Install LaTeX.
#
install_latex () {
msg "LaTeX is required for PDF generation, it could take up to several hours to install"
if is_mac; then
read -r -p "Would you like to install LaTeX now? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
brew cask install mactex
;;
*)
msg "You will not be able to generate PDF's without LaTeX"
;;
esac
else
sudo apt-get install texlive-full
fi
if [ $? -ne 0 ]; then
error "Could not install LaTeX."
exit 1
fi
verbose "Installed LaTeX"
}
if is_mac; then
install_homebrew
fi
install_rbenv
install_postgres
install_native_tools
install_dfire_dependencies
install_dstil_overcommit
install_latex
msg "You should now be able to launch the server with rails s"
verbose "Doubtfire should be successfuly Installed!"
exec $SHELL