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