added catalog scripts to build process
[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
52 function mkDir {
53         mkdir -p "$1";
54         [ "$?" != "0" ] && fail "Error creating $1";
55         [ ! -w "$1" ] && fail "We don't have write access to $1";
56 }
57
58 function mkInstallDirs {
59
60         installing      && mkDir "$PREFIX";
61         building        && mkDir "$TMP";
62         installing      && mkDir "$SOCK";
63         installing      && mkDir "$PID";
64         installing      && mkDir "$LOG";
65
66
67         # add the opensrf user and group
68          if installing; then
69                 if [ ! $(grep "^opensrf:" /etc/group) ]; then groupadd opensrf; fi
70                 if [ ! $(grep "^opensrf:" /etc/passwd) ]; then useradd -g opensrf opensrf; fi
71                 # add opensrf to the opensrf group
72                 gpasswd -a opensrf opensrf
73         fi;
74
75 }
76
77 function installing {
78         if [ -z "$INSTALLING" ]; then return 1; fi;
79         return 0;
80 }
81
82 function building {
83         if [ -z "$BUILDING" ]; then return 1; fi;
84         return 0;
85 }
86
87
88
89 # --------------------------------------------------------------------
90 # Loads the config file.  If it can't fine CONFIG_FILE, it attempts to
91 # use DEFAULT_CONFIG_FILE.  If it can't find that, it fails.
92 # --------------------------------------------------------------------
93 function loadConfig {
94         if [ ! -f "$CONFIG_FILE" ]; then
95                 if [ -f "$DEFAULT_CONFIG_FILE" ]; then
96                         echo "+ + + Copying $DEFAULT_CONFIG_FILE to $CONFIG_FILE and using its settings...";
97                         cp "$DEFAULT_CONFIG_FILE" "$CONFIG_FILE";
98                 else
99                         fail "config file \"$CONFIG_FILE\" cannot be found";
100                 fi
101         fi
102         source "$CONFIG_FILE";
103 }
104
105
106
107
108 function runInstall {
109
110
111
112         # pass the collected variables to make
113         for target in ${TARGETS[@]:0}; do
114
115                 echo ""
116                 echo "-------------- [ $target ] -------------------------------------------";
117                 echo ""
118
119                 MAKE="make $verbose APXS2=$APXS2 PREFIX=$PREFIX TMP=$TMP APR_HEADERS=$APR_HEADERS \
120                         APACHE2_HEADERS=$APACHE2_HEADERS LIBXML2_HEADERS=$LIBXML2_HEADERS DBPORT=$DBPORT\
121                         BINDIR=$BINDIR LIBDIR=$LIBDIR PERLDIR=$PERLDIR INCLUDEDIR=$INCLUDEDIR \
122                         WEBDIR=$WEBDIR TEMPLATEDIR=$TEMPLATEDIR ETCDIR=$ETCDIR REPORTERDIR=$REPORTERDIR\
123                         OPENSRFDIR=$OPENSRFDIR OPENILSDIR=$OPENILSDIR EVERGREENDIR=$EVERGREENDIR \
124                         CIRCRULESDIR=$CIRCRULESDIR CATALOGSCRIPTDIR=$CATALOGSCRIPTDIR CGIDIR=$CGIDIR \
125                         DBDRVR=$DBDRVR DBHOST=$DBHOST DATADIR=$DATADIR\
126                         PENALTYRULESDIR=$PENALTYRULESDIR DBNAME=$DBNAME DBUSER=$DBUSER DBPW=$DBPW XSLDIR=$XSLDIR NEW_OPAC_URL=$NEW_OPAC_URL \
127                         NEW_XUL_PACKAGE_NAME=$NEW_XUL_PACKAGE_NAME NEW_XUL_PACKAGE_LABEL=$NEW_XUL_PACKAGE_LABEL";
128
129
130                 case "$target" in
131         
132                         # OpenSRF ---                   
133
134                         "opensrf_all")
135                                 if building;    then $MAKE -C "$OPENSRFDIR" all; fi;
136                                 if installing; then $MAKE -C "$OPENSRFDIR" install; fi;
137                                 ;;
138
139                         "opensrf_jserver" )
140                                 if building;    then $MAKE -C "$OPENSRFDIR" "jserver"; fi;
141                                 if installing; then $MAKE -C "$OPENSRFDIR" "jserver-install"; fi;
142                                 ;;      
143
144                         "opensrf_router" ) 
145                                 if building;    then $MAKE -C "$OPENSRFDIR" "router"; fi;
146                                 if installing; then $MAKE -C "$OPENSRFDIR" "router-install"; fi;
147                                 ;;
148
149                         "opensrf_gateway" )
150                                 if building; then $MAKE -C "$OPENSRFDIR" "gateway"; fi;
151                                 if installing; then $MAKE -C "$OPENSRFDIR" "gateway-install"; fi;
152                                 ;;
153
154                         "opensrf_srfsh" ) 
155                                 if building;    then $MAKE -C "$OPENSRFDIR" "srfsh"; fi;
156                                 if installing; then $MAKE -C "$OPENSRFDIR" "srfsh-install"; fi;
157                                 ;;
158
159                         "opensrf_core" )
160                                 if building; then $MAKE -C "$OPENSRFDIR" libstack/opensrf; fi;
161                                 if installing; then $MAKE -C "$OPENSRFDIR" "perl-install"; fi;
162                                 ;;
163
164
165                         # OpenILS ---                   
166
167                         "openils_all" )
168                                 if building;    then $MAKE -C "$OPENILSDIR" all; fi;
169                                 if installing; then $MAKE -C "$OPENILSDIR" install; fi;
170                                 ;;
171
172                         "openils_core" )
173                                 if building; then $MAKE -C "$OPENILSDIR" "c_apps"; fi;
174                                 if installing; then 
175                                         $MAKE -C "$OPENILSDIR" "perl-install"; 
176                                         $MAKE -C "$OPENILSDIR" "string-templates-install"; 
177                                         $MAKE -C "$OPENILSDIR" "xsl-install"; 
178                                         $MAKE -C "$OPENILSDIR" "c_apps-install"; 
179                                         $MAKE -C "$OPENILSDIR" "circ_rules-install"; 
180                                 fi;
181                                 ;;
182
183                         "openils_web" )
184                                 if building; then $MAKE -C "$OPENILSDIR" "mod_xmlent"; fi;
185                                 if building; then $MAKE -C "$OPENILSDIR" "mod_ils_rest_gateway"; fi;
186                                 if installing; then
187                                         $MAKE -C "$OPENILSDIR" "web-install";
188                                         $MAKE -C "$OPENILSDIR" "cgi-bootstrap";
189                                         $MAKE -C "$OPENILSDIR" "reporter-install";
190                                 fi;
191                                 ;;
192
193                         "openils_marcdumper" )
194                                 if building;    then $MAKE -C "$OPENILSDIR" "marcdumper"; fi;
195                                 if installing; then $MAKE -C "$OPENILSDIR" "marcdumper-install"; fi;
196                                 ;;
197
198                         "openils_db" )
199                                 if installing; then 
200                                         $MAKE -C "$OPENILSDIR" "storage-bootstrap"; 
201                                 fi;
202                                 ;;
203
204                         "openils_reporter" )
205                                 if installing; then 
206                                         $MAKE -C "$OPENILSDIR" "reporter-install";
207                                 fi;
208                                 ;;
209
210                         "openils_client_xul" )
211                                 if building; then
212                                         $MAKE -C "$OPENILSDIR" "client-xul";
213                                 fi;
214                                 ;;
215
216                         "openils_server_xul" )
217                                 if installing; then
218                                         $MAKE -C "$OPENILSDIR" "server-xul";
219                                 fi;
220                                 ;;
221
222                         # Evergreen ---                         
223
224                         "evergreen_core" )
225                                 if installing;  then $MAKE -C "$EVERGREENDIR" "circ-install"; fi;
226                                 if installing;  then $MAKE -C "$EVERGREENDIR" "iplist-install"; fi;
227                                 if installing;  then $MAKE -C "$EVERGREENDIR" "perl-install"; fi;
228                                 ;;      
229
230                         "evergreen_xul_client" )
231                                 if building;    then $MAKE -C "$EVERGREENDIR" xul; fi;
232                                 ;;
233
234
235                         *) fail "Unknown target: $target";;
236
237                 esac
238
239         done
240
241         if installing; then
242                 echo -e "\nNow run: chown -R opensrf:opensrf $PREFIX"
243         fi
244 }
245
246
247 # --------------------------------------------------------------------
248 # Checks command line parameters for special behavior
249 # Supported params are:
250 # clean - cleans all build files
251 # build - builds the specified sources
252 # install - installs the specified sources
253 # --------------------------------------------------------------------
254 function checkParams {
255
256         if [ -z "$1" ]; then usage; fi;
257
258         for arg in "$@"; do
259
260                 lastArg="$arg";
261
262                 case "$arg" in
263
264                         "clean") 
265                                 cleanMe;;
266
267                         "build")
268                                 BUILDING="1";;
269
270                         "install")
271                                 INSTALLING="1";;
272                         
273                         "verbose")
274                                 verbose="";;
275
276                         *) fail "Unknown option => $arg";
277                 esac
278         done
279
280         if [ "$lastArg" = "clean" ]; then exit 0; fi;
281 }
282
283
284 function cleanMe {
285         loadConfig;
286         make "TMP=$TMP" -s -C "$OPENSRFDIR" clean;
287         make "TMP=$TMP" -s -C "$OPENILSDIR"  clean;
288         make "TMP=$TMP" -s -C "$EVERGREENDIR" clean;
289 }
290
291 function usage {
292         echo "usage: $0 [ build | install | clean ]";
293         exit;
294 }
295
296 checkParams "$@";
297
298 if building; then echo "Building..."; fi;
299 if installing; then echo "Installing..."; fi;
300
301
302 # --------------------------------------------------------------------
303 # Kick it off...
304 # --------------------------------------------------------------------
305 loadConfig;
306 mkInstallDirs;
307 runInstall;
308
309
310