throw error on "optimistic locking" failure detection
[Evergreen.git] / install.sh
1 #!/bin/bash
2 # --------------------------------------------------------------------
3 # Copyright (C) 2005  Georgia Public Library Service 
4 # Bill Erickson <highfalutin@gmail.com>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 # --------------------------------------------------------------------
16
17
18 # --------------------------------------------------------------------
19 # ILS install script
20 # --------------------------------------------------------------------
21 CONFIG_FILE="install.conf";
22 DEFAULT_CONFIG_FILE="install.conf.default";
23 verbose="-s" #clear this to get full build output
24
25
26 # --------------------------------------------------------------------
27 # Loads all of the path information from the user setting 
28 # install variables as it goes
29 # --------------------------------------------------------------------
30
31 function fail {
32         MSG="$1";
33         echo "A build error occured: $MSG";
34         exit 99;
35 }
36
37
38 #function postMessage {
39
40 #cat <<-WORDS
41 #       --------------------------------------------------------------------
42
43
44 #}
45
46
47
48 # --------------------------------------------------------------------
49 # Makes sure the install directories exist and are writable
50 # --------------------------------------------------------------------
51 function mkInstallDirs {
52
53         if installing; then
54
55                 mkdir -p "$PREFIX";
56                 if [ "$?" != "0" ]; then
57                         fail "Error creating $PREFIX";
58                 fi
59
60                 if [ ! -w "$PREFIX" ]; then
61                         fail "We don't have write access to $PREFIX";
62                 fi
63
64         fi
65
66         if building; then
67
68                 mkdir -p "$TMP";
69                 if [ "$?" != "0" ]; then
70                         fail "Error creating $TMP";
71                 fi
72
73                 if [ ! -w "$TMP" ]; then
74                         fail "We don't have write access to $TMP";
75                 fi
76         fi
77
78         
79
80 }
81
82 function installing {
83         if [ -z "$INSTALLING" ]; then return 1; fi;
84         return 0;
85 }
86
87 function building {
88         if [ -z "$BUILDING" ]; then return 1; fi;
89         return 0;
90 }
91
92
93
94 # --------------------------------------------------------------------
95 # Loads the config file.  If it can't fine CONFIG_FILE, it attempts to
96 # use DEFAULT_CONFIG_FILE.  If it can't find that, it fails.
97 # --------------------------------------------------------------------
98 function loadConfig {
99         if [ ! -f "$CONFIG_FILE" ]; then
100                 if [ -f "$DEFAULT_CONFIG_FILE" ]; then
101                         echo "+ + + Copying $DEFAULT_CONFIG_FILE to $CONFIG_FILE and using its settings...";
102                         cp "$DEFAULT_CONFIG_FILE" "$CONFIG_FILE";
103                 else
104                         fail "config file \"$CONFIG_FILE\" cannot be found";
105                 fi
106         fi
107         source "$CONFIG_FILE";
108 }
109
110
111
112
113 function runInstall {
114
115
116
117         # pass the collected variables to make
118         for target in ${TARGETS[@]:0}; do
119
120                 echo ""
121                 echo "-------------- [ $target ] -------------------------------------------";
122                 echo ""
123
124                 MAKE="make $verbose APXS2=$APXS2 PREFIX=$PREFIX TMP=$TMP \
125                         APACHE2_HEADERS=$APACHE2_HEADERS LIBXML2_HEADERS=$LIBXML2_HEADERS \
126                         BINDIR=$BINDIR LIBDIR=$LIBDIR PERLDIR=$PERLDIR INCLUDEDIR=$INCLUDEDIR \
127                         WEBDIR=$WEBDIR TEMPLATEDIR=$TEMPLATEDIR ETCDIR=$ETCDIR \
128                         OPENSRFDIR=$OPENSRFDIR OPENILSDIR=$OPENILSDIR EVERGREENDIR=$EVERGREENDIR \
129                         CIRCRULESDIR=$CIRCRULESDIR CGIDIR=$CGIDIR DBDRVR=$DBDRVR DBHOST=$DBHOST \
130                         DBNAME=$DBNAME DBUSER=$DBUSER DBPW=$DBPW XSLDIR=$XSLDIR NEW_OPAC_URL=$NEW_OPAC_URL \
131                         NEW_XUL_PACKAGE_NAME=$NEW_XUL_PACKAGE_NAME NEW_XUL_PACKAGE_LABEL=$NEW_XUL_PACKAGE_LABEL";
132
133
134                 case "$target" in
135         
136                         # OpenSRF ---                   
137
138                         "opensrf_all")
139                                 if building;    then $MAKE -C "$OPENSRFDIR" all; fi;
140                                 if installing; then $MAKE -C "$OPENSRFDIR" install; fi;
141                                 ;;
142
143                         "opensrf_jserver" )
144                                 if building;    then $MAKE -C "$OPENSRFDIR" "jserver"; fi;
145                                 if installing; then $MAKE -C "$OPENSRFDIR" "jserver-install"; fi;
146                                 ;;      
147
148                         "opensrf_router" ) 
149                                 if building;    then $MAKE -C "$OPENSRFDIR" "router"; fi;
150                                 if installing; then $MAKE -C "$OPENSRFDIR" "router-install"; fi;
151                                 ;;
152
153                         "opensrf_gateway" )
154                                 if building; then $MAKE -C "$OPENSRFDIR" "gateway"; fi;
155                                 if installing; then $MAKE -C "$OPENSRFDIR" "gateway-install"; fi;
156                                 ;;
157
158                         "opensrf_srfsh" ) 
159                                 if building;    then $MAKE -C "$OPENSRFDIR" "srfsh"; fi;
160                                 if installing; then $MAKE -C "$OPENSRFDIR" "srfsh-install"; fi;
161                                 ;;
162
163                         "opensrf_core" )
164                                 if installing; then $MAKE -C "$OPENSRFDIR" "perl-install"; fi;
165                                 ;;
166
167
168                         # OpenILS ---                   
169
170                         "openils_all" )
171                                 if building;    then $MAKE -C "$OPENILSDIR" all; fi;
172                                 if installing; then $MAKE -C "$OPENILSDIR" install; fi;
173                                 ;;
174
175                         "openils_core" )
176                                 if building; then $MAKE -C "$OPENILSDIR" "c_apps"; fi;
177                                 if installing; then 
178                                         $MAKE -C "$OPENILSDIR" "perl-install"; 
179                                         $MAKE -C "$OPENILSDIR" "string-templates-install"; 
180                                         $MAKE -C "$OPENILSDIR" "xsl-install"; 
181                                         $MAKE -C "$OPENILSDIR" "c_apps-install"; 
182                                 fi;
183                                 ;;
184
185                         "openils_web" )
186                                 if building; then $MAKE -C "$OPENILSDIR" "mod_xmltools"; fi;
187                                 if building; then $MAKE -C "$OPENILSDIR" "mod_ils_rest_gateway"; fi;
188                                 if installing; then $MAKE -C "$OPENILSDIR" "web-install"; fi;
189                                 if installing; then $MAKE -C "$OPENILSDIR" "cgi-bootstrap"; fi;
190                                 ;;
191
192                         "openils_marcdumper" )
193                                 if building;    then $MAKE -C "$OPENILSDIR" "marcdumper"; fi;
194                                 if installing; then $MAKE -C "$OPENILSDIR" "marcdumper-install"; fi;
195                                 ;;
196
197                         "openils_db" )
198                                 if installing; then 
199                                         $MAKE -C "$OPENILSDIR" "storage-bootstrap"; 
200                                 fi;
201                                 ;;
202
203
204                         # Evergreen ---                         
205
206                         "evergreen_core" )
207                                 if installing;  then $MAKE -C "$EVERGREENDIR" "circ-install"; fi;
208                                 ;;      
209
210                         "evergreen_xul_client" )
211                                 if building;    then $MAKE -C "$EVERGREENDIR" xul; fi;
212                                 ;;
213
214
215                         *) fail "Unknown target: $target";;
216
217                 esac
218
219         done
220 }
221
222
223 # --------------------------------------------------------------------
224 # Checks command line parameters for special behavior
225 # Supported params are:
226 # clean - cleans all build files
227 # build - builds the specified sources
228 # install - installs the specified sources
229 # --------------------------------------------------------------------
230 function checkParams {
231
232         if [ -z "$1" ]; then usage; fi;
233
234         for arg in "$@"; do
235
236                 lastArg="$arg";
237
238                 case "$arg" in
239
240                         "clean") 
241                                 cleanMe;;
242
243                         "build")
244                                 BUILDING="1";;
245
246                         "install")
247                                 INSTALLING="1";;
248                         
249                         "verbose")
250                                 verbose="";;
251
252                         *) fail "Unknown option => $arg";
253                 esac
254         done
255
256         if [ "$lastArg" = "clean" ]; then exit 0; fi;
257 }
258
259
260 function cleanMe {
261         loadConfig;
262         make "TMP=$TMP" -s -C "$OPENSRFDIR" clean;
263         make "TMP=$TMP" -s -C "$OPENILSDIR"  clean;
264         make "TMP=$TMP" -s -C "$EVERGREENDIR" clean;
265 }
266
267 function usage {
268         echo "usage: $0 [ build | install | clean ]";
269         exit;
270 }
271
272 checkParams "$@";
273
274 if building; then echo "Building..."; fi;
275 if installing; then echo "Installing..."; fi;
276
277
278 # --------------------------------------------------------------------
279 # Kick it off...
280 # --------------------------------------------------------------------
281 loadConfig;
282 mkInstallDirs;
283 runInstall;
284
285
286