root/main/trunk/greenstone2/gsicontrol.sh @ 24953

Revision 24953, 11.7 KB (checked in by ak19, 8 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 *
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# Need to remove extra quotes around $collecthome. ${string//abc/xyz} does a replace all on abc with xyz
108    cat "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf.in" \
109    | sed "s@\*\*GSDL_OS_ARCH\*\*@$GSDLOS$GSDLARCH@g" \
110    | sed "s@\*\*PORT\*\*@$port@g" \
111    | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
112    | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
113    | sed "s@\*\*HOSTS\*\*@$hosts@g" \
114    | sed "s@\*\*COLLECTHOME\*\*@${collecthome//\"/}@g" \
115    | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
116    | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH@g" \
117    | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
118    > "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ;
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
131    configfile=$1 ;
132# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
133    if [ "x$configfile" = "x" ]; then
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
137    configfile="$GSDLHOME/llssite.cfg";
138    fi ;
139    echo "Configuring the apache webserver..." ;
140    port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
141    hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
142    hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;   
143   
144    externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
145    if [ "x$externalaccess" = "x1" ] ; then
146    externalaccess="yes"
147    else
148    externalaccess="no"
149    fi
150
151    echo -e "$port\n$hostIP\n$hosts\n$externalaccess" | configure-port-and-connection ;
152    if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
153    echo $MONITOR_SUCCESS;
154    else
155    echo $MONITOR_FAILED;
156    fi
157    echo $MONITOR_FINISHED
158}
159
160function configure-web {
161    for one_file in gs2-server.app gli.app client-gli.app gems.app ; do     
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
166    fi
167    done ;
168
169    configure-cgi
170    configure-apache $1
171}
172
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
177function reset-gsdlhome {
178    echo "" ;
179    relocate=yes ;
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
183    if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
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" ;
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
197    else
198        relocate=
199    fi
200    fi 
201   
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 \
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
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   
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.
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
266}
267
268function web-status {
269    test-gsdlhome
270    $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl status
271}
272
273function web-start {
274    test-gsdlhome
275    $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl start
276    if [ $? = 0 ] ; then
277    echo $MONITOR_SUCCESS;
278    else
279    echo $MONITOR_FAILED;
280    fi
281    echo $MONITOR_FINISHED;
282}
283
284function web-restart {
285    test-gsdlhome
286    $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl restart
287    if [ $? = 0 ] ; then
288    echo $MONITOR_SUCCESS;
289    else
290    echo $MONITOR_FAILED;
291    fi
292    echo $MONITOR_FINISHED;
293}
294
295function web-graceful {
296    test-gsdlhome
297    $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl graceful
298    if [ $? = 0 ] ; then
299    echo $MONITOR_SUCCESS;
300    else
301    echo $MONITOR_FAILED;
302    fi
303    echo $MONITOR_FINISHED;
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
309# been done.  This avoids an unnecessary repetition of printing
310# out the values of GSDLHOME and GSDLOS
311    if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
312    $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl stop ;
313    fi
314}
315
316function web-stop {
317    test-gsdlhome
318    web-stop-tested
319    if [ $? = 0 ] ; then
320    echo $MONITOR_SUCCESS;
321    else
322    echo $MONITOR_FAILED;
323    fi
324    echo $MONITOR_FINISHED;
325}
326
327function usage {
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"
337    echo "   configure-web [config-filename]"
338    echo "   configure-apache [config-filename]"
339    echo "   configure-cgi"
340    echo "   reset-gsdlhome [config-filename]"
341    echo "        (Save a copy of $cgibin/gsdlsite.cfg to preserve any customisations)"
342    echo "   test-gsdlhome"
343    echo "   web-stop-tested"
344    echo ""
345}
346
347
348if [[ $# < 1  || $# > 2 ]] ; then
349    usage
350    exit 0
351fi
352
353target=$1
354configfile=$2
355
356# remove any extraneous double quotes
357configfile=${configfile//\"/}
358
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)
373    configure-web $configfile;;
374    configure-apache)
375    configure-apache $configfile;;
376    configure-cgi)
377    configure-cgi;;
378    set-port)
379    configure-port-and-connection;;
380    reset-gsdlhome)
381    reset-gsdlhome;;
382    test-gsdlhome)
383    test-gsdlhome;;
384    web-stop-tested)
385    web-stop-tested;;
386    *)
387    echo
388        echo "Command unrecognised: $target"
389    usage;;
390
391esac
392
393# jump back to directory we originally got called from
394cd "$storedir"
395exit;
Note: See TracBrowser for help on using the browser.