much work toward the dtd-on-the-fly architecture for locale changing
[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
24
25 # --------------------------------------------------------------------
26 # Loads all of the path information from the user setting 
27 # install variables as it goes
28 # --------------------------------------------------------------------
29
30 function fail {
31         MSG="$1";
32         echo "A build error occured: $MSG";
33         exit 99;
34 }
35
36
37 #function postMessage {
38
39 #cat <<-WORDS
40 #       --------------------------------------------------------------------
41
42
43 #}
44
45
46
47 # --------------------------------------------------------------------
48 # Makes sure the install directories exist and are writable
49 # --------------------------------------------------------------------
50 function mkInstallDirs {
51
52         if installing; then
53
54                 mkdir -p "$PREFIX";
55                 if [ "$?" != "0" ]; then
56                         fail "Error creating $PREFIX";
57                 fi
58
59                 if [ ! -w "$PREFIX" ]; then
60                         fail "We don't have write access to $PREFIX";
61                 fi
62
63         fi
64
65         if building; then
66
67                 mkdir -p "$TMP";
68                 if [ "$?" != "0" ]; then
69                         fail "Error creating $TMP";
70                 fi
71
72                 if [ ! -w "$TMP" ]; then
73                         fail "We don't have write access to $TMP";
74                 fi
75         fi
76
77         
78
79 }
80
81 function installing {
82         if [ -z "$INSTALLING" ]; then return 1; fi;
83         return 0;
84 }
85
86 function building {
87         if [ -z "$BUILDING" ]; then return 1; fi;
88         return 0;
89 }
90
91
92
93 # --------------------------------------------------------------------
94 # Loads the config file.  If it can't fine CONFIG_FILE, it attempts to
95 # use DEFAULT_CONFIG_FILE.  If it can't find that, it fails.
96 # --------------------------------------------------------------------
97 function loadConfig {
98         if [ ! -f "$CONFIG_FILE" ]; then
99                 if [ -f "$DEFAULT_CONFIG_FILE" ]; then
100                         echo "+ + + Copying $DEFAULT_CONFIG_FILE to $CONFIG_FILE and using its settings...";
101                         cp "$DEFAULT_CONFIG_FILE" "$CONFIG_FILE";
102                 else
103                         fail "config file \"$CONFIG_FILE\" cannot be found";
104                 fi
105         fi
106         source "$CONFIG_FILE";
107 }
108
109
110
111
112 function runInstall {
113
114
115
116         # pass the collected variables to make
117         for target in ${TARGETS[@]:0}; do
118
119                 cat <<-MSG
120
121                 --------------------------------------------------------------------
122                 Building $target
123                 --------------------------------------------------------------------
124
125                 MSG
126
127                 MAKE="make APXS2=$APXS2 PREFIX=$PREFIX TMP=$TMP \
128                         APACHE2_HEADERS=$APACHE2_HEADERS LIBXML2_HEADERS=$LIBXML2_HEADERS \
129                         BINDIR=$BINDIR LIBDIR=$LIBDIR PERLDIR=$PERLDIR INCLUDEDIR=$INCLUDEDIR \
130                         WEBDIR=$WEBDIR TEMPLATEDIR=$TEMPLATEDIR ETCDIR=$ETCDIR \
131                         OPENSRFDIR=$OPENSRFDIR OPENILSDIR=$OPENILSDIR EVERGREENDIR=$EVERGREENDIR \
132                         CIRCRULESDIR=$CIRCRULESDIR CGIDIR=$CGIDIR DBDRVR=$DBDRVR DBHOST=$DBHOST \
133                         DBNAME=$DBNAME DBUSER=$DBUSER DBPW=$DBPW XSLDIR=$XSLDIR NEW_OPAC_URL=$NEW_OPAC_URL \
134                         NEW_XUL_PACKAGE_NAME=$NEW_XUL_PACKAGE_NAME NEW_XUL_PACKAGE_LABEL=$NEW_XUL_PACKAGE_LABEL";
135
136
137                 case "$target" in
138         
139                         # OpenSRF ---                   
140
141                         "opensrf_all")
142                                 if building;    then $MAKE -C "$OPENSRFDIR" all; fi;
143                                 if installing; then $MAKE -C "$OPENSRFDIR" install; fi;
144                                 ;;
145
146                         "opensrf_jserver" )
147                                 if building;    then $MAKE -C "$OPENSRFDIR" "jserver"; fi;
148                                 if installing; then $MAKE -C "$OPENSRFDIR" "jserver-install"; fi;
149                                 ;;      
150
151                         "opensrf_router" ) 
152                                 if building;    then $MAKE -C "$OPENSRFDIR" "router"; fi;
153                                 if installing; then $MAKE -C "$OPENSRFDIR" "router-install"; fi;
154                                 ;;
155
156                         "opensrf_gateway" )
157                                 if building;    then 
158                                         $MAKE -C "$OPENSRFDIR" "gateway"; 
159                                         $MAKE -C "$OPENSRFDIR" "rest_gateway"; 
160                                 fi;
161
162                                 if installing; then $MAKE -C "$OPENSRFDIR" "gateway-install"; fi;
163                                 ;;
164
165                         "opensrf_srfsh" ) 
166                                 if building;    then $MAKE -C "$OPENSRFDIR" "srfsh"; fi;
167                                 if installing; then $MAKE -C "$OPENSRFDIR" "srfsh-install"; fi;
168                                 ;;
169
170                         "opensrf_core" )
171                                 if installing; then $MAKE -C "$OPENSRFDIR" "perl-install"; fi;
172                                 ;;
173
174
175                         # OpenILS ---                   
176
177                         "openils_all" )
178                                 if building;    then $MAKE -C "$OPENILSDIR" all; fi;
179                                 if installing; then $MAKE -C "$OPENILSDIR" install; fi;
180                                 ;;
181
182                         "openils_core" )
183                                 if installing; then 
184                                         $MAKE -C "$OPENILSDIR" "perl-install"; 
185                                         $MAKE -C "$OPENILSDIR" "string-templates-install"; 
186                                         $MAKE -C "$OPENILSDIR" "xsl-install"; 
187                                 fi;
188                                 ;;
189
190                         "openils_web" )
191                                 if building; then $MAKE -C "$OPENILSDIR" "mod_xmltools"; fi;
192                                 if installing; then $MAKE -C "$OPENILSDIR" "web-install"; fi;
193                                 ;;
194
195                         "openils_marcdumper" )
196                                 if building;    then $MAKE -C "$OPENILSDIR" "marcdumper"; fi;
197                                 if installing; then $MAKE -C "$OPENILSDIR" "marcdumper-install"; fi;
198                                 ;;
199
200                         "openils_db" )
201                                 if installing; then 
202                                         $MAKE -C "$OPENILSDIR" "storage-bootstrap"; 
203                                 fi;
204                                 ;;
205
206
207                         # Evergreen ---                         
208
209                         "evergreen_core" )
210                                 if installing;  then $MAKE -C "$EVERGREENDIR" "images-install"; fi;
211                                 if installing;  then $MAKE -C "$EVERGREENDIR" "circ-install"; fi;
212                                 if installing;  then $MAKE -C "$EVERGREENDIR" "css-install"; fi;
213                                 ;;      
214
215                         "evergreen_xul_client" )
216                                 if building;    then $MAKE -C "$EVERGREENDIR" xul; fi;
217                                 ;;
218
219
220                         *) fail "Unknown target: $target";;
221
222                 esac
223
224         done
225 }
226
227
228 # --------------------------------------------------------------------
229 # Checks command line parameters for special behavior
230 # Supported params are:
231 # clean - cleans all build files
232 # build - builds the specified sources
233 # install - installs the specified sources
234 # --------------------------------------------------------------------
235 function checkParams {
236
237         if [ -z "$1" ]; then return; fi;
238
239         for arg in "$@"; do
240
241                 lastArg="$arg";
242
243                 case "$arg" in
244
245                         "clean") 
246                                 cleanMe;;
247
248                         "build")
249                                 BUILDING="1";;
250
251                         "install")
252                                 INSTALLING="1";;
253
254                         *) fail "Unknown command line argument: $arg";;
255                 esac
256         done
257
258         if [ "$lastArg" = "clean" ]; then exit 0; fi;
259 }
260
261
262 function cleanMe {
263         loadConfig;
264         make -C "$OPENSRFDIR" clean;
265         make -C "$OPENILSDIR"  clean;
266         make -C "$EVERGREENDIR" clean;
267 }
268
269 checkParams "$@";
270
271
272 if building; then echo "Building..."; fi;
273 if installing; then echo "Installing..."; fi;
274
275
276 # --------------------------------------------------------------------
277 # Kick it off...
278 # --------------------------------------------------------------------
279 loadConfig;
280 mkInstallDirs;
281 runInstall;
282
283
284