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