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