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