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

Last change on this file since 27065 was 24953, checked in by ak19, 12 years ago

For non-standard collecthome specified in gsdlsite.cfg on linux, need to remove any extraneous quotes around collecthome before writing it into the apache httpd.conf file.

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