root/gsdl/trunk/gsicontrol.sh @ 20619

Revision 20619, 6.4 KB (checked in by ak19, 10 years ago)

1. Changes to get localhost to be recognised on Linux and the hostname to be recognised on Windows. Multiple allowed host values are inserted into the configfile (e.g. llssite.cfg) and these are used in httpd.conf. 2. Fixed errors: the Address Resolution Method part of the GSI dialog should not be deactivated when the Allow External Connections is checked.

  • Property svn:executable set to *
Line 
1#!/bin/bash
2
3testdone=0
4
5function test-gsdlhome {
6    if [ $testdone == "0" ] ; then
7        if test -z "$GSDLHOME" ; then
8        echo "" ;
9        echo "Environment variable GSDLHOME not set." ;
10        echo "  This needs to be set to run this gsicontrol command." ;
11        echo "  Have you run 'source setup.bash'?" ;
12        echo "" ;
13        exit 1
14        else
15        echo "Using: " ;
16        echo "  GSDLHOME = $GSDLHOME" ;
17        echo "  GSDLOS   = $GSDLOS" ;
18        fi
19    testdone=1
20    fi
21
22
23function configure-cgi {
24    test-gsdlhome
25    if test ! -e $GSDLHOME/cgi-bin/gsdlsite.cfg ; then
26    echo "Configuring cgi-bin/gsdlsite.cfg" ;
27    sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg ;
28    else
29    echo "WARNING: Nothing done for make configure-cgi." ;
30    echo "   If you wish to regenerate the file " ;
31    echo "   $GSDLHOME/cgi-bin/gsdlsite.cfg" ;
32    echo "   from scratch, delete the existing file first." ;
33    fi
34}
35
36function configure-admin {
37    test-gsdlhome
38    echo "" ;
39    echo "Configuring admin user password:" ;
40    encrypted_password=`getpw` ;
41    if [ $? = "0" ] ; then
42    echo -e "[admin]\n<enabled>true\n<groups>administrator,colbuilder,all-collections-editor\n<password>$encrypted_password\n<username>admin" \
43        | txt2db -append "$GSDLHOME/etc/users.gdb" ;
44    else
45    echo "Did not set password" ;
46    fi
47    echo ""
48}
49
50
51function configure-port-and-connection {
52    test-gsdlhome
53    configfile=$1 ;
54# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
55    if [ "x$configfile" = "x" ]; then
56    if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
57        cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
58    fi
59    configfile="$GSDLHOME/llssite.cfg";
60    fi ;
61
62    if test -e "$configfile" ; then
63    hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
64    if [ "$hostIP" != "127.0.0.1" ] ; then
65        hostIP="127.0.0.1 $hostIP"
66    fi
67    else
68    hostIP="127.0.0.1"
69    fi
70
71    echo "Enter port number to use:"
72    read port ;
73    echo "Enter allowed hosts to use ($hostIP localhost <hostname>) separated by spaces:"
74    read hosts ;
75    echo "Allow external connections [yes/no]:"
76    read connection ;   
77    if [ $connection = "yes" ] || [ $connection = "y" ] ; then
78        allowfromall="Allow"
79    else
80    allowfromall="Deny"
81    fi
82
83    if test ! -z $port ; then
84    echo "Port: $port" ;
85    echo "Stopping web server (if running)" ;
86    web-stop-tested ;
87    echo "Setting config file to use port $port";
88    cat "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf.in" \
89    | sed "s@\*\*PORT\*\*@$port@g" \
90    | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
91    | sed "s@\*\*HOSTS\*\*@$hosts@g" \
92    | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
93    | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS@g" \
94    > "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ;
95    echo "Type '$0 web-start' to start the web server running on port $port" ;
96    fi ;
97    echo "Done" ;
98}
99
100
101MONITOR_SUCCESS="MAKE SUCCESSFUL"
102MONITOR_FAILED="MAKE FAILED"
103MONITOR_FINISHED="MAKE DONE"
104
105function configure-apache {
106    test-gsdlhome
107    configfile=$1 ;
108# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
109    if [ "x$configfile" = "x" ]; then
110    if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
111        cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
112    fi
113    configfile="$GSDLHOME/llssite.cfg";
114    fi ;
115    echo "Configuring the apache webserver..." ;
116    port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
117    hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;
118   
119    externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
120    if [ $externalaccess == "1" ] ; then
121    externalaccess="yes"
122    else
123    externalaccess="no"
124    fi
125
126    echo -e "$port\n$hosts\n$externalaccess" | configure-port-and-connection ;
127    if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
128    echo $MONITOR_SUCCESS;
129    else
130    echo $MONITOR_FAILED;
131    fi
132    echo $MONITOR_FINISHED
133}
134
135function configure-web {
136    configure-cgi
137    configure-apache $1
138}
139
140function web-status {
141    test-gsdlhome
142    $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl status
143}
144
145function web-start {
146    test-gsdlhome
147    $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl start
148    if [ $? = 0 ] ; then
149    echo $MONITOR_SUCCESS;
150    else
151    echo $MONITOR_FAILED;
152    fi
153    echo $MONITOR_FINISHED;
154}
155
156function web-restart {
157    test-gsdlhome
158    $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart
159    if [ $? = 0 ] ; then
160    echo $MONITOR_SUCCESS;
161    else
162    echo $MONITOR_FAILED;
163    fi
164    echo $MONITOR_FINISHED;
165}
166
167function web-graceful {
168    test-gsdlhome
169    $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful
170    if [ $? = 0 ] ; then
171    echo $MONITOR_SUCCESS;
172    else
173    echo $MONITOR_FAILED;
174    fi
175    echo $MONITOR_FINISHED;
176}
177
178function web-stop-tested {
179# This version runs without testing for GSDLHOME
180# Useful to be run as a target when we know test-gsdlhome has already
181# been done.  This avoids a unnecessary repetition of printing
182# out the values of GSDLHOME and GSDLOS
183    if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
184    $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl stop ;
185    fi
186}
187
188function web-stop {
189    test-gsdlhome
190    web-stop-tested
191    if [ $? = 0 ] ; then
192    echo $MONITOR_SUCCESS;
193    else
194    echo $MONITOR_FAILED;
195    fi
196    echo $MONITOR_FINISHED;
197}
198
199function usage {
200    echo ""
201    echo "   Usage: $0 <command>"
202    echo "          where <command> is any of the following: "
203    echo "   web-start"
204    echo "   web-stop"
205    echo "   web-restart"
206    echo "   web-status"
207    echo "   web-graceful"
208    echo "   configure-admin"
209    echo "   configure-web [config-filename]"
210    echo "   configure-apache [config-filename]"
211    echo "   configure-cgi"
212    echo "   test-gsdlhome"
213    echo "   web-stop-tested"
214    echo ""
215}
216
217
218if [[ $# < 1  || $# > 2 ]] ; then
219    usage
220    exit 0
221fi
222
223target=$1
224configfile=$2
225
226case $target in
227    web-start)
228    web-start;;
229    web-stop)
230    web-stop;;
231    web-restart)
232    web-restart;;
233    web-status)
234    web-status;;
235    web-graceful)
236    web-graceful;;
237    configure-admin)
238    configure-admin;;
239    configure-web)
240    configure-web $configfile;;
241    configure-apache)
242    configure-apache $configfile;;
243    configure-cgi)
244    configure-cgi;;
245    set-port)
246    configure-port-and-connection;;
247    test-gsdlhome)
248    test-gsdlhome;;
249    web-stop-tested)
250    web-stop-tested;;
251    *)
252    echo
253        echo "Command unrecognised: $target"
254    usage;;
255
256esac
257
258exit;
Note: See TracBrowser for help on using the browser.