source: main/trunk/greenstone2/gsicontrol.sh@ 24295

Last change on this file since 24295 was 24295, checked in by ak19, 13 years ago

Fixed a bug introduced with the reset-gsdlhome target where any non-standard collecthome value written into the gsdlsite.cfg was lost on startup since reset-gsdlhome always regenerated gsdlsite.cfg from the template file. Now the collecthome property is reinstated when the gsdlsite.cfg is generated, by taking this from the gsdlsite.cfg.bak file.

  • Property svn:executable set to *
File size: 11.0 KB
Line 
1#!/bin/bash
2
3storedir="`pwd`"
4thisdir="`dirname \"$0\"`"
5thisdir="`cd \"$thisdir\" && pwd`"
6cd "$thisdir"
7source setup.bash
8
9testdone=0
10
11cgibin="cgi-bin"
12if [ -d "cgi-bin/$GSDLOS$GSDLARCH" ] ; then
13 cgibin="cgi-bin/$GSDLOS$GSDLARCH"
14fi
15
16
17function test-gsdlhome {
18 if [ $testdone == "0" ] ; then
19 if test -z "$GSDLHOME" ; then
20 echo "" ;
21 echo "Environment variable GSDLHOME not set." ;
22 echo " This needs to be set to run this gsicontrol command." ;
23 echo " Have you run 'source setup.bash'?" ;
24 echo "" ;
25 exit 1
26 else
27 echo "Using: " ;
28 echo " GSDLHOME = $GSDLHOME" ;
29 echo " GSDLOS = $GSDLOS" ;
30 fi
31 testdone=1
32 fi
33}
34
35function configure-cgi {
36 test-gsdlhome
37 if test ! -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
38 echo "Configuring $cgibin/gsdlsite.cfg" ;
39 echo "# **** This file is automatically generated, do not edit ****" > "$cgibin/gsdlsite.cfg" ;
40 echo "# For local customization of Greenstone, edit gsdlsite.cfg.in" >> "$cgibin/gsdlsite.cfg" ;
41 echo "" >> "$cgibin/gsdlsite.cfg" ;
42 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "$cgibin/gsdlsite.cfg.in" >> "$cgibin/gsdlsite.cfg" ;
43# preserve the user-assigned collecthome property, if any
44 if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg.bak" ; then
45 collecthome=`egrep "^collecthome" "$cgibin/gsdlsite.cfg.bak" | awk '{print $2}'` ;
46 if test -n $collecthome ; then
47 echo "collecthome $collecthome" >> "$cgibin/gsdlsite.cfg" ;
48 echo "" >> "$cgibin/gsdlsite.cfg" ;
49 fi
50 fi
51 else
52 echo "WARNING: Nothing done for make configure-cgi." ;
53 echo " If you wish to regenerate the file " ;
54 echo " $GSDLHOME/$cgibin/gsdlsite.cfg" ;
55 echo " from scratch, delete the existing file first." ;
56 fi
57}
58
59function configure-admin {
60 test-gsdlhome
61 echo "" ;
62 echo "Configuring admin user password:" ;
63 encrypted_password=`getpw` ;
64 if [ $? = "0" ] ; then
65 echo -e "[admin]\n<enabled>true\n<groups>administrator,colbuilder,all-collections-editor\n<password>$encrypted_password\n<username>admin" \
66 | txt2db -append "$GSDLHOME/etc/users.gdb" ;
67 else
68 echo "Did not set password" ;
69 fi
70 echo ""
71}
72
73
74function configure-port-and-connection {
75 test-gsdlhome
76
77 echo "Enter port number to use:"
78 read port ;
79 echo "Enter host IP to allow (127.0.0.1 is included by default):"
80 read hostIP ;
81 echo "Enter hostname or list of hosts to allow (localhost included by default):"
82 read hosts ;
83 echo "Allow external connections [yes/no]:"
84 read connection ;
85 if [ "x$connection" = "xyes" ] || [ "x$connection" = "xy" ] ; then
86 allowfromall="Allow"
87 else
88 allowfromall="Deny"
89 fi
90
91 lib_path_var="LD_LIBRARY_PATH" ;
92 if [ $GSDLOS = "darwin" ] ; then
93 lib_path_var="DYLD_LIBRARY_PATH"
94 fi
95
96 if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
97 collecthome=`egrep "^collecthome" "$GSDLHOME/$cgibin/gsdlsite.cfg" | awk '{print $2}'` ;
98 fi
99 if test -z $collecthome ; then
100 collecthome="$GSDLHOME/collect" ;
101 fi
102
103 if test ! -z $port ; then
104 echo "Port: $port" ;
105# if called by reset-gsdlhome, then httpd.conf file was regenerated by install-bindist.sh script and
106# contains placeholder strings, including for Listen port. So can't stop web-server in such a case.
107 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
108 confport=`egrep "^Listen" $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf | awk '{print $2}'` ;
109 if [ "$confport" != "**PORT**" ] ; then
110 echo "Stopping web server (if running)" ;
111 web-stop-tested ;
112 fi
113 fi
114 echo "Setting config file to use port $port";
115 cat "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf.in" \
116 | sed "s@\*\*PORT\*\*@$port@g" \
117 | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
118 | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
119 | sed "s@\*\*HOSTS\*\*@$hosts@g" \
120 | sed "s@\*\*COLLECTHOME\*\*@$collecthome@g" \
121 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
122 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH@g" \
123 | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
124 > "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ;
125 echo "Type '$0 web-start' to start the web server running on port $port" ;
126 fi ;
127 echo "Done" ;
128}
129
130
131MONITOR_SUCCESS="MAKE SUCCESSFUL"
132MONITOR_FAILED="MAKE FAILED"
133MONITOR_FINISHED="MAKE DONE"
134
135function configure-apache {
136 test-gsdlhome
137 configfile=$1 ;
138# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
139 if [ "x$configfile" = "x" ]; then
140 if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
141 cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
142 fi
143 configfile="$GSDLHOME/llssite.cfg";
144 fi ;
145 echo "Configuring the apache webserver..." ;
146 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
147 hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
148 hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;
149
150 externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
151 if [ "x$externalaccess" = "x1" ] ; then
152 externalaccess="yes"
153 else
154 externalaccess="no"
155 fi
156
157 echo -e "$port\n$hostIP\n$hosts\n$externalaccess" | configure-port-and-connection ;
158 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
159 echo $MONITOR_SUCCESS;
160 else
161 echo $MONITOR_FAILED;
162 fi
163 echo $MONITOR_FINISHED
164}
165
166function configure-web {
167 for one_file in gs2-server.app gli.app client-gli.app gems.app ; do
168 if test ! -e "$one_file/Contents/document.wflow" ; then
169 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "$one_file/Contents/document.wflow.in" > "$one_file/Contents/document.wflow"
170 fi
171 done ;
172
173 configure-cgi
174 configure-apache $1
175}
176
177# forces configure-cgi by deleting gsdlsite.cfg
178function reset-gsdlhome {
179 echo "" ;
180 if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
181 /bin/mv "$GSDLHOME/$cgibin/gsdlsite.cfg" "$GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
182 echo "**** Regenerating $GSDLHOME/$cgibin/gsdlsite.cfg" ;
183 echo "**** Previous version of file now $GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
184 fi
185
186 apache_home_os="$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH"
187
188 if test ! -e "$apache_home_os/bin/apachectl.in" ; then
189 make apache-for-dist
190 fi
191
192 replace_list="conf/extra/httpd-dav.conf \
193 conf/extra/httpd-manual.conf \
194 conf/extra/httpd-autoindex.conf \
195 conf/extra/httpd-vhosts.conf \
196 conf/extra/httpd-ssl.conf \
197 conf/extra/httpd-multilang-errordoc.conf \
198 conf/original/extra/httpd-dav.conf \
199 conf/original/extra/httpd-manual.conf \
200 conf/original/extra/httpd-autoindex.conf \
201 conf/original/extra/httpd-vhosts.conf \
202 conf/original/extra/httpd-ssl.conf \
203 conf/original/extra/httpd-multilang-errordoc.conf \
204 conf/original/httpd.conf\
205 lib/apr-util-1/apr_dbd_odbc.la \
206 lib/apr-util-1/apr_dbd_sqlite3.la \
207 lib/pkgconfig/apr-util-1.pc \
208 lib/pkgconfig/apr-1.pc \
209 lib/libaprutil-1.la \
210 lib/libapr-1.la \
211 build/config_vars.mk \
212 build/config.nice \
213 build/apr_rules.mk \
214 bin/dbmmanage \
215 bin/apu-1-config \
216 bin/apr-1-config \
217 include/ap_config_auto.h \
218 include/ap_config_layout.h"
219
220 for one_file in apachectl envvars envvars-std ; do
221 /bin/cp "$apache_home_os/bin/$one_file.in" "$apache_home_os/bin/$one_file"
222 done
223
224 for one_file in $replace_list ; do
225 /bin/cp "$apache_home_os/$one_file.in" "$apache_home_os/$one_file"
226 done
227
228 /bin/cp "$apache_home_os/bin/apr-1-config.in" "$apache_home_os/bin/apr-1-config"
229
230 /bin/cp "$apache_home_os/bin/apu-1-config.in" "$apache_home_os/bin/apu-1-config"
231
232 /bin/cp "$apache_home_os/build/config_vars.mk.in" "$apache_home_os/build/config_vars.mk"
233
234# replace template files with active versions. The following will generate a httpd.conf
235# file with placeholder strings, all of which we'll replace shortly hereafter.
236 bash "$apache_home_os/install-bindist.sh" "$apache_home_os"
237
238 log4jprop=$GSDLHOME/lib/java/log4j.properties
239 sed "s^@gsdl2home@^$GSDLHOME^g" "$log4jprop.in" > "$log4jprop"
240
241 for one_file in gs2-server.app gli.app client-gli.app gems.app ; do
242 if test -e "$one_file/Contents/document.wflow" ; then
243 rm -f "$one_file/Contents/document.wflow"
244 fi
245 done
246
247 configure-web $1
248}
249
250function web-status {
251 test-gsdlhome
252 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl status
253}
254
255function web-start {
256 test-gsdlhome
257 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl start
258 if [ $? = 0 ] ; then
259 echo $MONITOR_SUCCESS;
260 else
261 echo $MONITOR_FAILED;
262 fi
263 echo $MONITOR_FINISHED;
264}
265
266function web-restart {
267 test-gsdlhome
268 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl restart
269 if [ $? = 0 ] ; then
270 echo $MONITOR_SUCCESS;
271 else
272 echo $MONITOR_FAILED;
273 fi
274 echo $MONITOR_FINISHED;
275}
276
277function web-graceful {
278 test-gsdlhome
279 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl graceful
280 if [ $? = 0 ] ; then
281 echo $MONITOR_SUCCESS;
282 else
283 echo $MONITOR_FAILED;
284 fi
285 echo $MONITOR_FINISHED;
286}
287
288function web-stop-tested {
289# This version runs without testing for GSDLHOME
290# Useful to be run as a target when we know test-gsdlhome has already
291# been done. This avoids an unnecessary repetition of printing
292# out the values of GSDLHOME and GSDLOS
293 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
294 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl stop ;
295 fi
296}
297
298function web-stop {
299 test-gsdlhome
300 web-stop-tested
301 if [ $? = 0 ] ; then
302 echo $MONITOR_SUCCESS;
303 else
304 echo $MONITOR_FAILED;
305 fi
306 echo $MONITOR_FINISHED;
307}
308
309function usage {
310 echo ""
311 echo " Usage: $0 <command>"
312 echo " where <command> is any of the following: "
313 echo " web-start"
314 echo " web-stop"
315 echo " web-restart"
316 echo " web-status"
317 echo " web-graceful"
318 echo " configure-admin"
319 echo " configure-web [config-filename]"
320 echo " configure-apache [config-filename]"
321 echo " configure-cgi"
322 echo " reset-gsdlhome [config-filename]\n\t(Save a copy of $cgibin/gsdlsite.cfg to preserve any customisations)"
323 echo " test-gsdlhome"
324 echo " web-stop-tested"
325 echo ""
326}
327
328
329if [[ $# < 1 || $# > 2 ]] ; then
330 usage
331 exit 0
332fi
333
334target=$1
335configfile=$2
336
337# remove any extraneous double quotes
338configfile=${configfile//\"/}
339
340case $target in
341 web-start)
342 web-start;;
343 web-stop)
344 web-stop;;
345 web-restart)
346 web-restart;;
347 web-status)
348 web-status;;
349 web-graceful)
350 web-graceful;;
351 configure-admin)
352 configure-admin;;
353 configure-web)
354 configure-web $configfile;;
355 configure-apache)
356 configure-apache $configfile;;
357 configure-cgi)
358 configure-cgi;;
359 set-port)
360 configure-port-and-connection;;
361 reset-gsdlhome)
362 reset-gsdlhome;;
363 test-gsdlhome)
364 test-gsdlhome;;
365 web-stop-tested)
366 web-stop-tested;;
367 *)
368 echo
369 echo "Command unrecognised: $target"
370 usage;;
371
372esac
373
374# jump back to directory we originally got called from
375cd "$storedir"
376exit;
Note: See TracBrowser for help on using the repository browser.