Merge pull request #31 from xtuple/master
[xtuple] / update.sh
1 #!/bin/bash 
2 PRODUCTION=''
3 HOST='localhost'
4
5 usage()
6 {
7    cat << EOF
8    usage: $0 options
9    update the environment
10    OPTIONS:
11    -h target host
12    -p production mode
13 EOF
14 }       
15 while getopts ":ph:" opt; do
16   case $opt in
17     p)
18       PRODUCTION=true
19       echo 'production mode'
20       ;;
21     h)
22       HOST=$OPTARG
23       ;;
24     ?)
25       usage
26       exit
27       ;;
28   esac
29 done
30
31 # update source
32
33 git checkout master
34 if [ $? != 0  ]
35   then
36     echo "error checking out master"
37     exit $?
38 fi
39
40 git pull
41 if [ $? != 0  ]
42   then
43     echo "error pulling master"
44     exit $?
45 fi
46
47 if [ $PRODUCTION ]
48   then
49   git checkout `git describe --abbrev=0`
50   if [ $? != 0  ]
51     then
52       echo "error checking out latest tag"
53       exit $?
54   fi
55 fi
56
57 # update libraries
58 git submodule update --init --recursive
59 if [ $? != 0  ]
60   then
61     echo "error updating submodules"
62     exit $?
63 fi
64 cd node-datasource
65 npm install
66
67 # restart the datasource
68 monit stop node
69 sleep 10
70 monit start node
71 sleep 10
72
73 # update global db
74 cd database/source
75 psql -U admin  -h $HOST global -f init_global.sql
76 cd ../../installer
77 ./installer.js -h $HOST -d global -u admin -p 5432 -P admin --path ../database/orm
78
79 # update instance dbs
80 cd ..
81 node runMaintenance.js
82
83 # build extensions
84 cd ../enyo-client/extensions
85 ./tools/buildExtensions.sh
86
87 # deploy enyo client
88 cd ../application
89 rm -rf deploy
90 cd tools
91 ./deploy.sh