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

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

GSIControl.sh' reset-gsdlhome target should update the path to perl at the top of the gliserver.pl file to use the new gsdlhome. This was necessary for the equivalent Windows batch script, but the change is carried over to the .sh script for consistency.

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