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

Revision 24901, 11.6 KB (checked in by ak19, 8 years ago)

GSDLARCH used in Linux makefiles when working out the cgi-bin path (now cgi-bin\GSDL_OS_ARCH) to install the binaries into.

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