root/gsdl/trunk/gsicontrol.sh @ 20637

Revision 20637, 5.8 KB (checked in by ak19, 10 years ago)

1. Many changes to gsicontrol.bat to bring it up to date with the recent changes made to gsicontrol.sh. The httpd.conf.in now has a HOST_IP placeholder instead of HOSTS for the Allow From line. Now the httpd.conf always has at least the home IP (127.0.0.1) as well as the hostIP we write. These ensure that the local URLs localhost and hostname work on Linux and Windows. Other changes: the restart label is implemented differently and other minor corrections. 2. Minor spelling correction to gsicontrol.sh

  • 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
54    echo "Enter port number to use:"
55    read port ;
56    echo "Enter host IP to allow (127.0.0.1 is included by default):"
57    read hostIP ;
58    echo "Allow external connections [yes/no]:"
59    read connection ;   
60    if [ $connection = "yes" ] || [ $connection = "y" ] ; then
61        allowfromall="Allow"
62    else
63    allowfromall="Deny"
64    fi
65
66    if test ! -z $port ; then
67    echo "Port: $port" ;
68    echo "Stopping web server (if running)" ;
69    web-stop-tested ;
70    echo "Setting config file to use port $port";
71    cat "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf.in" \
72    | sed "s@\*\*PORT\*\*@$port@g" \
73    | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
74    | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
75    | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
76    | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS@g" \
77    > "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ;
78    echo "Type '$0 web-start' to start the web server running on port $port" ;
79    fi ;
80    echo "Done" ;
81}
82
83
84MONITOR_SUCCESS="MAKE SUCCESSFUL"
85MONITOR_FAILED="MAKE FAILED"
86MONITOR_FINISHED="MAKE DONE"
87
88function configure-apache {
89    test-gsdlhome
90    configfile=$1 ;
91# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
92    if [ "x$configfile" = "x" ]; then
93    if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
94        cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
95    fi
96    configfile="$GSDLHOME/llssite.cfg";
97    fi ;
98    echo "Configuring the apache webserver..." ;
99    port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
100    hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
101   
102    externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
103    if [ $externalaccess == "1" ] ; then
104    externalaccess="yes"
105    else
106    externalaccess="no"
107    fi
108
109    echo -e "$port\n$hostIP\n$externalaccess" | configure-port-and-connection ;
110    if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
111    echo $MONITOR_SUCCESS;
112    else
113    echo $MONITOR_FAILED;
114    fi
115    echo $MONITOR_FINISHED
116}
117
118function configure-web {
119    configure-cgi
120    configure-apache $1
121}
122
123function web-status {
124    test-gsdlhome
125    $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl status
126}
127
128function web-start {
129    test-gsdlhome
130    $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl start
131    if [ $? = 0 ] ; then
132    echo $MONITOR_SUCCESS;
133    else
134    echo $MONITOR_FAILED;
135    fi
136    echo $MONITOR_FINISHED;
137}
138
139function web-restart {
140    test-gsdlhome
141    $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart
142    if [ $? = 0 ] ; then
143    echo $MONITOR_SUCCESS;
144    else
145    echo $MONITOR_FAILED;
146    fi
147    echo $MONITOR_FINISHED;
148}
149
150function web-graceful {
151    test-gsdlhome
152    $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful
153    if [ $? = 0 ] ; then
154    echo $MONITOR_SUCCESS;
155    else
156    echo $MONITOR_FAILED;
157    fi
158    echo $MONITOR_FINISHED;
159}
160
161function web-stop-tested {
162# This version runs without testing for GSDLHOME
163# Useful to be run as a target when we know test-gsdlhome has already
164# been done.  This avoids an unnecessary repetition of printing
165# out the values of GSDLHOME and GSDLOS
166    if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
167    $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl stop ;
168    fi
169}
170
171function web-stop {
172    test-gsdlhome
173    web-stop-tested
174    if [ $? = 0 ] ; then
175    echo $MONITOR_SUCCESS;
176    else
177    echo $MONITOR_FAILED;
178    fi
179    echo $MONITOR_FINISHED;
180}
181
182function usage {
183    echo ""
184    echo "   Usage: $0 <command>"
185    echo "          where <command> is any of the following: "
186    echo "   web-start"
187    echo "   web-stop"
188    echo "   web-restart"
189    echo "   web-status"
190    echo "   web-graceful"
191    echo "   configure-admin"
192    echo "   configure-web [config-filename]"
193    echo "   configure-apache [config-filename]"
194    echo "   configure-cgi"
195    echo "   test-gsdlhome"
196    echo "   web-stop-tested"
197    echo ""
198}
199
200
201if [[ $# < 1  || $# > 2 ]] ; then
202    usage
203    exit 0
204fi
205
206target=$1
207configfile=$2
208
209case $target in
210    web-start)
211    web-start;;
212    web-stop)
213    web-stop;;
214    web-restart)
215    web-restart;;
216    web-status)
217    web-status;;
218    web-graceful)
219    web-graceful;;
220    configure-admin)
221    configure-admin;;
222    configure-web)
223    configure-web $configfile;;
224    configure-apache)
225    configure-apache $configfile;;
226    configure-cgi)
227    configure-cgi;;
228    set-port)
229    configure-port-and-connection;;
230    test-gsdlhome)
231    test-gsdlhome;;
232    web-stop-tested)
233    web-stop-tested;;
234    *)
235    echo
236        echo "Command unrecognised: $target"
237    usage;;
238
239esac
240
241exit;
Note: See TracBrowser for help on using the browser.