forked from mlegendre/canvas_local_install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal_install.sh
425 lines (314 loc) · 11.4 KB
/
local_install.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#!/bin/bash
ROOT_DIR=$PWD
CANVAS_ROOT_DIR=~/Desktop/code/canvas-lms
OS_ENV=("Darwin" "Ubuntu")
#This shell script will be used to automate a new environment
#TODO list
#
# Need to check for RVM and either use it or remove it.
#
# Work on general refactoring
#
# Make the .ssh directory check work, it should work but its not :(
#
# Refactor ideas:
#
# Add the following to make the code nicer
#while true; do
# read -p "Do you wish to install this program?" yn
# case $yn in
# [Yy]* ) make install; break;;
# [Nn]* ) exit;;
# * ) print_dash "Please answer yes or no.";;
# esac
#done
function beginning(){
print_dash "This script will be used to create a new local canvas-lms instance"
cd ~
}
#Future feature that will allow you to install canvas on any OS
function os_check(){
platform='uknown'
unamestr=`uname`
if [[ "$unamestr" == 'Darwin' ]]; then
platform='linux'
elif [[ "$unamestr" == 'Linux' ]]; then
platform='freebsd'
fi
#Need to figure out how to get this installed on Windows still (Don't laugh im being serious, it would open us up for school using windows OS)
}
function command_line_tools(){
XTOOLS_CHECK=`xcode-select -p`
XTOOLS_FOLDER='/Applications/Xcode.app/Contents/Developer'
NAME_OF_TOOLS="commandline_tools_os_x_mavericks_for_xcode__march_2014.dmg"
NAME_OF_WGET="wget-1.12-0.dmg"
WGET_URL="https://rudix.googlecode.com/files/wget-1.12-0.dmg"
DROPBOX_URL="https://www.dropbox.com/s/gqfz32662ol6bpe/commandline_tools_os_x_mavericks_for_xcode__march_2014.dmg"
ESCAPED_TOOL_NAME="/Volumes/Command\ Line\ Developer\ Tools/"
#TODO
# Check for xtools installed?
# xcode-select -p
# Should see this /Applications/Xcode.app/Contents/Developer
# Need to DRY the hdiutil commands up, could probably stick the following into a method of its own
# hdiutil attach <dmg>
# sudo installer -verbose -pkg
# hdiutil detach <dmg>
# rm <dmg>
if [[ $XTOOLS_CHECK == $XTOOLS_FOLDER ]];
then
print_dash "You already have xtools installed and I am going to skip this part of the installation"
else
print_dash "Now Downloading wget and installing xtools, please follow all prompts (You will need to enter your password)"
#Install wget
curl -O -k $WGET_URL
if [[ "$?" == 1 ]];
then
print_dash_error "The curl command did not work. Please check the URL and try again."
fi
hdiutil attach $NAME_OF_WGET
sudo installer -verbose -pkg /Volumes/wget.pkg/wget.pkg -target /
hdiutil detach /Volumes/wget.pkg
rm wget-1.12-0.dmg
#Use wget to grab commandline tools
wget -O $NAME_OF_TOOLS $DROPBOX_URL --no-check-certificate
if [[ "$?" == 1 ]];
then
print_dash_error "The wget command did not work. Please check the URL and try again."
fi
hdiutil attach $NAME_OF_TOOLS
#TODO figure out how to get rid of UI prompt
sudo installer -verbose -pkg /Volumes/Command\ Line\ Developer\ Tools/Command\ Line\ Tools\ \(OS\ X\ 10.9\).pkg -target /
hdiutil detach $ESCAPED_TOOL_NAME
rm $NAME_OF_TOOLS
fi
}
function rbenv_install(){
ruby_version_manager=''
#sudo apt-get install curl
cd $ROOT_DIR
print_dash "I am now going to install rbenv"
print_dash "Now modifying bash profile to set up rbenv"
touch ~/.bash_profile
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
print_dash "I am now installing rbenv xmlsec1 and nodejs"
brew install rbenv ruby-build xmlsec1 node
print_dash "I will now set up your system for rbenv with ruby 1.9.3 but you can always change this later"
rbenv install 1.9.3-p448
rbenv global 1.9.3-p448
}
function github_install(){
SSH_DIRECTORY="$ROOT_DIR/.ssh"
print_dash "Installing github on your machine"
brew install git
if ssh-add -L;
then
print_dash "Copying the first public ssh key listed in your agent to your clipboard"
ssh-add -L | head -1 | pbcopy
else
if [ ! -d "$SSH_DIRECTORY" ];
then
print_dash $'I see you do not have ssh keys on your system, wait while I generate those for you\nJust press enter when it asks where you want the key to reside and passphrase (makes it easier to find later)'
ssh-keygen
fi
print_dash "Copying your public ssh key to your clipboard"
pbcopy < ~/.ssh/id_rsa.pub
fi
}
function setting_up_gerrit_hooks(){
print_dash "If you haven't yet you need to set up a gerrit profile"
print_dash $'*Your public key is already in your clipboard*\n1. Go to https://gerrit.instructure.com\n2. Click "Sign In" in the upper-right corner\n3. Sign in with your LDAP credentials. (Talk to IT if you don\'t have any yet.)\n4. Add an SSH key on the registration page\n5. Ask BrianP, Simon, PaulH or Cody for Developer rights'
open 'http://gerrit.instructure.com'
waiting_for_user
read -p $'Now we will set up your gerrit hooks\nWhat is your gerrit login name? ' USER
if [[ -e ~/.ssh/config ]] && [[ -e ~/.gitconfig ]];
then
print_dash_warning "Seems you have already set up your .ssh config file. You might want to revisit that and make sure it is set up properly"
else
touch ~/.ssh/config
printf "Host gerrit
HostName gerrit.instructure.com
User $USER
Port 29418" >> ~/.ssh/config
printf "[color]
ui = true
[user]
name = $USER
email = [email protected]" >> ~/.gitconfig
fi
}
function waiting_for_user(){
print_dash "Would you like more time?"
read answer
while [ $answer == "y" ];
do
print_dash "I will give you some more time"
sleep 3m
print_dash "do you still need more time?"
read answer
done
}
function postgresql_install(){
print_dash "I am now going to download the newest postgressql on your system"
brew install postgresql
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
}
function canvas-lms_download(){
print_dash "Downloading canvas-lms"
name=$(git config --global instructure.name)
user=$(git config --global instructure.user)
gerrit_host=$(git config --global instructure.gerrithost)
gerrit_port=$(git config --global instructure.gerritport)
project=canvas-lms
target_dir=~/Desktop/code/canvas-lms
if [ "$name" == "" ] || [ "$user" == "" ]; then
while true; do
read -p "please enter your name: " name
read -p "please enter your instructure ldap username: " user
read -p "is \"$name ([email protected])\" right? [y/N] " yn
case $yn in
[Yy]* ) break;;
esac
done
git config --global instructure.name "$name"
git config --global instructure.user "$user"
fi
if [ "$gerrit_host" == "" ] || [ "$gerrit_port" == "" ]; then
gerrit_host=gerrit.instructure.com
gerrit_port=29418
git config --global instructure.gerrithost $gerrit_host
git config --global instructure.gerritport $gerrit_port
fi
git clone ssh://$user@$gerrit_host:$gerrit_port/$project $target_dir
cd ~/Desktop/code/canvas-lms
for config in delayed_jobs domain file_store outgoing_mail security; \
do cp config/$config.yml.example config/$config.yml; done
scp -p gerrit:hooks/commit-msg .git/hooks/
}
# This function will modify the database/secuity/environments YAML files
function setup_config_files(){
#TODO Need the outgoing mail yml configured
string_to_replace="facdd3a131ddd8988b14f6e4e01039c93cfa0160"
random=$(openssl rand -base64 20)
# config_replacments=( )
#This modifies the database yml file
cp config/database.yml.example config/database.yml
sed -i.bak 's/ queue:/ #queue:/' config/database.yml
sed -i.bak 's/ adapter: postgresql/ # adapter: postgresql/' config/database.yml
sed -i.bak 's/ encoding: utf8/ # encoding: utf8/' config/database.yml
sed -i bak 's/ timeout: 5000/ # timeout: 5000/' config/database.yml
sed -i.bak 's/ database: canvas_queue_development/ # database: canvas_queue_development/' config/database.yml
sed -i.bak 's/ database: canvas_queue_production/ #database: canvas_queue_production/' config/database.yml
sed -i.bak 's/ host: localhost/ #host: localhost/' config/database.yml
sed -i.bak 's/ username: canvas/ #username: canvas/' config/database.yml
sed -i.bak 's/ password: your_password/ #password: your_password/' config/database.yml
rm config/database.yml.bak
# This modifies the security.yml file
sed -i.bak 's/ facdd3a131ddd8988b14f6e4e01039c93cfa0160/ '$random'/' config/security.yml
# Need to modify the outgoingmail.yml file
#This modifies the envirnoments file
touch config/environments/development-local.rb
printf "config.cache_classes = true
config.action_controller.perform_caching = true
config.action_view.cache_template_loading = true" >> config/environments/development-local.rb
}
function install_bundler(){
print_dash "Now installing bundler gem"
cd ~/Desktop/code/canvas-lms
gem install bundler --version "=1.5.1"
}
function load_initial_data(){
bundle config build.thrift --with-cppflags='-D_FORTIFY_SOURCE=0'
bundle install --without mysql
bundle exec rake db:create
if [[ ! "$?" == 0 ]];
then
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
fi
bundle exec rake db:migrate
if [[ ! "$?" == 0 ]];
then
print_dash_error "Something happeend while creating the database. Is your server running?"
exit
fi
bundle exec rake db:load_initial_data
}
function download_cleanBranch_script(){
print_dash "Downloading cleanbranch script"
cd $CANVAS_ROOT_DIR
wget https://raw.github.com/mlegendre/personalprojects/master/cleanBranch.sh --no-check-certificate
if [[ ! "$?" == 0 ]];
then
print_dash_error "Something happened downloading my cleanBranch script. Did I move it? You will never know."
fi
print_dash "Spinning up your server now using cleanBranch.sh, make sure to run that script to checkout patchsets"
npm install
sed -i.bak 's/marc/'$USER'/' cleanBranch.sh
rm cleanBranch.sh.bak
chmod +x cleanBranch.sh
source $CANVAS_ROOT_DIR/cleanBranch.sh
}
# This function just checks to make sure the functions work
# This function just takes a string and adds a bunch of #'s to the bottom and top of the string
function print_dash() {
for (( x=0; x < ${#1}; x++ )); do
printf "#"
done
echo ""
printf '\e[38;5;46m%-6s\e[m' "$1"
echo ""
for (( x=0; x < ${#1}; x++ )); do
printf "#"
done
echo ""
}
function print_dash_error() {
for (( x=0; x < ${#1}; x++ )); do
printf "#"
done
echo ""
printf '\e[38;5;124m%-6s\e[m' "$1"
echo ""
for (( x=0; x < ${#1}; x++ )); do
printf "#"
done
echo ""
}
function print_dash_warning() {
for (( x=0; x < ${#1}; x++ )); do
printf "#"
done
echo ""
printf '\e[38;5;226m%-6s\e[m' "$1"
echo ""
for (( x=0; x < ${#1}; x++ )); do
printf "#"
done
echo ""
}
beginning
command_line_tools
which -s brew
if [[ $? != 0 ]] ; then
print_dash "You do not have homebrew installed please wait while I get that set up"
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
brew doctor
brew update
else
echo "You have homebrew installed already"
fi
github_install
setting_up_gerrit_hooks
postgresql_install
rbenv_install
source ~/.bash_profile
rbenv rehash
canvas-lms_download
setup_config_files
install_bundler
rbenv rehash
load_initial_data
download_cleanBranch_script