]> git.evergreen-ils.org Git - working/Evergreen.git/blob - build/tools/update.sh
Be sure to copy new JS files from OpenSRF on a FULL update/install
[working/Evergreen.git] / build / tools / update.sh
1 #!/bin/bash
2 #
3 # Author: Joe Atzberger, Equinox Software, Inc.
4 # License: GPL v2 or greater.
5
6 # Based on initial version by Bill Erickson.
7
8 function svn_or_git {
9     echo -en "###########\nUpdating source directory:" `pwd` "\n";
10     if [ -d "./.git" ]; then
11         if [ -d "./.git/svn/trunk" ]; then
12             git svn fetch;
13             # git svn rebase origin || die_msg "git svn rebase origin failed";
14         else
15             git fetch;
16             # git rebase origin || die_msg "git rebase origin failed";
17         fi
18     else
19         echo "Remember to run svn update as needed";
20         # svn update || die_msg "svn update failed";
21     fi
22 }
23
24 function feedback {
25 cat <<END_OF_FEEDBACK
26 Running with options:
27     CLEAN = ${OPT_CLEAN:-no}
28      FULL = ${OPT_FULL:-no}
29   VERBOSE = ${OPT_VERBOSE:-no}
30
31 Using Directories --
32   OpenSRF repo   : ${OSRF:-Missing}
33   OpenILS repo   : ${ILS:-Missing}
34   OpenILS install: ${INSTALL:-Missing}
35       XUL install: ${XUL:-Missing}
36
37 END_OF_FEEDBACK
38 }
39
40 function usage {
41     cat <<END_OF_USAGE
42 usage: $0 [-e /eg_trunk] [-i /openils_dir] [-s /srf_trunk] [-[cfbvt]]
43
44 PARAMETERS:
45    -e  specify Evergreen (OpenILS) source repository (default pwd)
46    -i  specify Evergreen installed directory (default /openils)
47    -s  specify OpenSRF source repository (default ~/OpenSRF/trunk)
48
49 All parameters are optional, but you will probably need to use -e and -i.
50
51 OPTIONS:
52    -c  clean: run make clean before make
53    -f  full: make both packages, do OpenSRF make install (usually not required)
54    -t  test: gives feedback but does not run anything
55    -v  verbose
56
57 The purpose of this script is to consolidate a lot of the annoying
58 and error-prone tasks associated with an upgrade for a developer.
59
60 Considerations:
61  * Run as opensrf user
62  * opensrf needs sudo 
63  * Assumes opensrf has OpenILS and OpenSRF repositories as svn or git-svn 
64    checkouts and both have been configured (as in ./configure) 
65   
66 END_OF_USAGE
67 }
68
69 function die_msg {
70     echo -e "ERROR: ${1:-Unknown}\n" >&2;
71     usage;
72     exit 1;
73 }
74
75 # ----------------------------------
76 # Prespond to command-line options
77 # ----------------------------------
78 while getopts  "cfhtvb:e:i:s:" flag; do
79     case $flag in   
80         "b") OPT_BASEDIR="$OPTARG";;    # HIDDEN (undocumented) option.
81         "e") OPT_EGDIR="$OPTARG"  ;;
82         "i") OPT_INSTALL="$OPTARG";;
83         "s") OPT_OSRFDIR="$OPTARG";;
84         "c") OPT_CLEAN=1  ;;
85         "f") OPT_FULL=1   ;;
86         "t") OPT_TEST=1   ;;
87         "v") OPT_VERBOSE=1;;
88         "h"|*) usage && exit;;
89     esac;
90 done
91
92 # ----------------------------------
93 # DEFAULTS (w/ optional overrides)
94 # ----------------------------------
95 INSTALL=${OPT_INSTALL:-/openils};
96 BASE=~      # default to $HOME (~ doesn't like :- syntax for whatever reason)
97 [ -z "$OPT_BASEDIR" ] || BASE="$OPT_BASEDIR";
98
99 OSRF=${OPT_OSRFDIR:-$BASE/OpenSRF/trunk};
100 ILS=${OPT_EGDIR:-$(pwd)};
101 XUL="$INSTALL/var/web/xul";
102 JSDIR="$INSTALL/lib/javascript";    # only used for FULL install
103
104 # ----------------------------------
105 # TEST and SANITY CHECK
106 # ----------------------------------
107 [ ! -d "$ILS"     ]   && die_msg "Evergreen Source Directory '$ILS' does not exist!";
108 [ ! -d "$INSTALL" ]   && die_msg "Evergreen Install Directory '$INSTALL' does not exist!";
109 [ ! -d "$XUL"     ]   && die_msg "Evergreen XUL Client Directory '$XUL' does not exist!";
110 [ ! -d "$OSRF"    ]   && die_msg "OpenSRF Source Directory '$OSRF' does not exist!";
111 which sudo >/dev/null || die_msg "sudo not installed (or in PATH)";
112
113 [ -d "${ILS}/.svn" ] || [ -d "${ILS}/.git" ] || [ -d ${ILS}/.bzr ] || die_msg "Evergreen Source Directory '$ILS' is not a SVN, bzr or git repo";
114
115 if [ ! -z "$OPT_TEST" ] ; then
116     feedback;
117     exit;
118 fi
119
120 # ----------------------------------
121 # MAIN
122 # ----------------------------------
123 if [ -n "$OPT_FULL"  ]; then
124     echo; echo; echo '*** Performing FULL installation ***' ; echo; echo;
125 fi
126 if [ -z "$OPT_VERBOSE" ] ; then
127     echo "Running with some make output suppressed.  To see all output, run $0 with -v (verbose)";
128     echo "This may take a few minutes... ";
129     exec 3>&1          # Save current STDOUT to FD3
130     exec 1>/dev/null   # redirect (not close) STDOUT
131 else
132     feedback;
133     echo -e "Password prompts are triggered by sudo (as this user)\nStopping Apache.";
134     set -x;     # echo commands to screen
135 fi
136
137 sudo /etc/init.d/apache2 stop;
138 $INSTALL/bin/osrf_ctl.sh -l -a stop_all;
139
140 # OpenSRF perl directory is not shared.  update the drone
141 # ssh 10.5.0.202 "./update_osrf_perl.sh";
142
143 cd $OSRF; svn_or_git;
144 cd $ILS;  svn_or_git;
145
146 if [ -n "$OPT_CLEAN" ]; then
147     cd $OSRF && make clean;
148     cd $ILS  && make clean;
149 fi
150
151 if [ -n "$OPT_FULL"  ]; then
152     cd $OSRF && make;
153     cd $ILS  && make;
154     cd $OSRF && sudo make install;
155     if [ -d "$JSDIR" ]; then
156         echo "Copying OpenSRF javascript files into $JSDIR";
157         cp ./src/javascript/* $JSDIR;
158     fi
159 fi
160 sudo chown -R opensrf:opensrf $INSTALL
161
162 BIDDATE=$(date +"%Y-%m-%dT%H:%M:%S");
163 BID=${STAFF_CLIENT_BUILD_ID:-$BIDDATE};   # or "current"
164
165 rm -f "$XUL/current" || rm -rf "$XUL/current";      # removing the old link/build
166 cd $ILS && sudo make install STAFF_CLIENT_STAMP_ID=$BID STAFF_CLIENT_BUILD_ID=$BID;
167 sudo chown -R opensrf:opensrf $INSTALL
168
169 [ -d "$XUL/$BID" ] || die_msg "New build directory $XUL/$BID was not created.  sudo make install failed?";
170
171 if [ -z "$OPT_VERBOSE" ] ; then
172     exec 1>&3   # Restore STDOUT
173 fi
174
175 cd $XUL || die_msg "Could not cd to $XUL";
176 pwd;
177 rm -f $XUL/current-client-build.zip;
178 cp -r "$ILS/Open-ILS/xul/staff_client/build" ./
179 zip -rq current-client-build.zip build;
180 echo -n "BUILD_ID: ";
181 cat ./build/BUILD_ID;
182 echo -n "STAMP_ID: ";
183 cat ./build/STAMP_ID;
184 echo -n " VERSION: ";
185 cat ./build/VERSION;
186 rm -rf ./build;
187
188 echo "build ID is '$BID'";
189
190 if [ "$BID" != "$BIDDDATE" ] ; then
191     mv $BID $BIDDATE;    # Move the non-timestamp directory to timestamp-based spot
192     ln -s $BIDDATE $BID; # link back to it
193 fi
194
195 rm -f current;      # removing the link to the old build
196 ln -s $BIDDATE current; # linking "current" to the new build
197
198 rm -f server;
199 ln -s current/server server;
200     
201
202 sudo chown -R opensrf:opensrf $OSRF $ILS
203 $INSTALL/bin/osrf_ctl.sh -l -a start_all
204 sleep 2;
205 cd $INSTALL/bin; ./autogen.sh ../conf/opensrf_core.xml;
206 sudo /etc/init.d/apache2 start;
207
208 echo $'done\a'  # \a = Bell character for beep