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