forked from NZOI/nztrain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.sh
executable file
·59 lines (40 loc) · 1.69 KB
/
update.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
#!/bin/bash
for ARG in "$@"
do
case $ARG in
"--skip-pull")
gitpull=false
;;
*)
;;
esac
done
# change pwd to RAILS ROOT (the directory this script resides in)
cd `dirname $0`
# note, we are bashing the echoes so that "sh update.sh" will still print coloured output
# optional: mark website down (.htaccess url rewrite or other similar)
if ${gitpull:=true} ; then
# pull from git
bash -c "echo -e '\E[34m\033[1mgit pull\033[0m'"
git pull | sed -e 's/^/ /g;' | cat # sed to indent output
fi
# install new gems required
bash -c "echo -e '\E[34m\033[1mbundle install\033[0m'"
bundle install | sed -e 's/^/ /g;/Using/{:a;N;$!ba;s/Using [0-9a-z_ -]\+\(([0-9.]\+) \)\?\n//g}' | cat # sed indents, remove output of un-upgraded gems
# Stop WEBrick/Apache server here (only if database needs migration?)
# migrate database
bash -c "echo -e '\E[34m\033[1mbundle exec rake db:migrate\033[0m'"
bundle exec rake db:migrate | sed -e 's/^/ /g;' | cat # sed to indent output
# reseed database if necessary
bash -c "echo -e '\E[34m\033[1mbundle exec rake db:seed\033[0m'"
bundle exec rake db:seed | sed -e 's/^/ /g;' | cat # sed to indent output
# can restart server here
# update cron jobs (whenever cronjobs tagged with the rails directory name)
cmd="bundle exec whenever --update-crontab `basename \`pwd\``"
bash -c "echo -e '\E[34m\033[1m$cmd\033[0m'"
$cmd
# precompile assets (if in production mode)
bash -c "echo -e '\E[34m\033[1mbundle exec rake assets:precompile\033[0m'"
bundle exec rake assets:precompile | sed -e 's/^/ /g;' | cat # sed to indent output
# Start WEBrick/Apache server here
# If using Phusion Passenger, touch tmp/restart.txt can restart Rails