]> git.evergreen-ils.org Git - working/Evergreen.git/blob - build/tools/update.sh
e735dacabdf529b8992f3a2e73897b92a68d0ab0
[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.  
62  * opensrf needs sudo 
63  * Assumes opensrf has a configured (as in ./configure) both ILS and 
64    OpenSRF as svn or git-svn checkouts
65 END_OF_USAGE
66 }
67
68 function die_msg {
69     echo -e "ERROR: ${1:-Unknown}\n" >&2;
70     usage;
71     exit 1;
72 }
73
74 # ----------------------------------
75 # Prespond to command-line options
76 # ----------------------------------
77 while getopts  "cfhtvb:e:i:s:" flag; do
78     case $flag in   
79         "b") OPT_BASEDIR="$OPTARG";;    # HIDDEN (undocumented) option.
80         "e") OPT_EGDIR="$OPTARG"  ;;
81         "i") OPT_INSTALL="$OPTARG";;
82         "s") OPT_OSRFDIR="$OPTARG";;
83         "c") OPT_CLEAN=1  ;;
84         "f") OPT_FULL=1   ;;
85         "t") OPT_TEST=1   ;;
86         "v") OPT_VERBOSE=1;;
87         "h"|*) usage && exit;;
88     esac;
89 done
90
91 # ----------------------------------
92 # DEFAULTS (w/ optional overrides)
93 # ----------------------------------
94 INSTALL=${OPT_INSTALL:-/openils};
95 BASE=~      # default to $HOME (~ doesn't like :- syntax for whatever reason)
96 [ -z "$OPT_BASEDIR" ] || BASE="$OPT_BASEDIR";
97
98 OSRF=${OPT_OSRFDIR:-$BASE/OpenSRF/trunk};
99 ILS=${OPT_EGDIR:-$(pwd)};
100 XUL="$INSTALL/var/web/xul";
101
102 # ----------------------------------
103 # TEST and SANITY CHECK
104 # ----------------------------------
105 [ ! -d "$ILS"     ]   && die_msg "Evergreen Source Directory '$ILS' does not exist!";
106 [ ! -d "$INSTALL" ]   && die_msg "Evergreen Install Directory '$INSTALL' does not exist!";
107 [ ! -d "$XUL"     ]   && die_msg "Evergreen XUL Client Directory '$XUL' does not exist!";
108 [ ! -d "$OSRF"    ]   && die_msg "OpenSRF Source Directory '$OSRF' does not exist!";
109 which sudo >/dev/null || die_msg "sudo not installed (or in PATH)";
110
111 [ -d "${ILS}/.svn" ] || [ -d "${ILS}/.git" ] || die_msg "Evergreen Source Directory '$ILS' is not a SVN or git repo";
112
113 if [ ! -z "$OPT_TEST" ] ; then
114     feedback;
115     exit;
116 fi
117
118 # ----------------------------------
119 # MAIN
120 # ----------------------------------
121 if [ -n "$OPT_FULL"  ]; then
122     echo; echo; echo '*** Performing FULL installation ***' ; echo; echo;
123 fi
124 if [ -z "$OPT_VERBOSE" ] ; then
125     echo "Running with some make output suppressed.  To see all output, run $0 with -v (verbose)";
126     echo "This may take a few minutes... ";
127     exec 3>&1          # Save current STDOUT to FD3
128     exec 1>/dev/null   # redirect (not close) STDOUT
129 else
130     feedback;
131     echo -e "Password prompts are triggered by sudo (as this user)\nStopping Apache.";
132     set -x;     # echo commands to screen
133 fi
134
135 sudo /etc/init.d/apache2 stop;
136 $INSTALL/bin/osrf_ctl.sh -l -a stop_all;
137
138 # OpenSRF perl directory is not shared.  update the drone
139 # ssh 10.5.0.202 "./update_osrf_perl.sh";
140
141 cd $OSRF; svn_or_git;
142 cd $ILS;  svn_or_git;
143
144 if [ -n "$OPT_CLEAN" ]; then
145     cd $OSRF && make clean;
146     cd $ILS  && make clean;
147 fi
148
149 if [ -n "$OPT_FULL"  ]; then
150     cd $OSRF && make;
151     cd $ILS  && make;
152     cd $OSRF && sudo make install;
153 fi
154 sudo chown -R opensrf:opensrf $INSTALL
155
156 BID=$(date +"%Y-%m-%dT%H:%M:%S");   # or "current"
157 cd $ILS && sudo make install STAFF_CLIENT_BUILD_ID=$BID;
158 sudo chown -R opensrf:opensrf $INSTALL
159
160 [ -d "$XUL/$BID" ] || die_msg "New build directory $XUL/$BID was not created.  sudo make install failed?"
161
162 if [ -z "$OPT_VERBOSE" ] ; then
163     exec 1>&3   # Restore STDOUT
164 fi
165
166 cd $XUL || die_msg "Could not cd to $XUL";
167 pwd;
168 rm -f $XUL/current-client-build.zip;
169 cp -r "$ILS/Open-ILS/xul/staff_client/build" ./
170 zip -rq current-client-build.zip build;
171 cat ./build/BUILD_ID
172 rm -rf ./build;
173
174
175 rm -f current;      # removing the link to the old build
176 ln -s $BID current; # linking "current" to the new build
177 ln -s current/server server;
178     
179
180 sudo chown -R opensrf:opensrf $OSRF $ILS
181 $INSTALL/bin/osrf_ctl.sh -l -a start_all
182 sleep 2;
183 cd $INSTALL/bin; ./autogen.sh ../conf/opensrf_core.xml;
184 sudo /etc/init.d/apache2 start;
185