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