source: gsdl/trunk/gsicontrol.sh@ 20619

Last change on this file since 20619 was 20619, checked in by ak19, 15 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 *
File size: 6.4 KB
RevLine 
[18851]1#!/bin/bash
2
[19250]3testdone=0
4
[18851]5function test-gsdlhome {
[19250]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
[18851]20 fi
[19250]21}
[18851]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" \
[19140]43 | txt2db -append "$GSDLHOME/etc/users.gdb" ;
[18851]44 else
45 echo "Did not set password" ;
46 fi
47 echo ""
48}
49
[19250]50
[20619]51function configure-port-and-connection {
[18851]52 test-gsdlhome
[20619]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
[18851]71 echo "Enter port number to use:"
72 read port ;
[20619]73 echo "Enter allowed hosts to use ($hostIP localhost <hostname>) separated by spaces:"
74 read hosts ;
[19250]75 echo "Allow external connections [yes/no]:"
[20619]76 read connection ;
[19250]77 if [ $connection = "yes" ] || [ $connection = "y" ] ; then
[20619]78 allowfromall="Allow"
79 else
80 allowfromall="Deny"
[19250]81 fi
82
[18851]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" \
[20619]90 | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
91 | sed "s@\*\*HOSTS\*\*@$hosts@g" \
[18851]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
[18866]107 configfile=$1 ;
[19023]108# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
[18866]109 if [ "x$configfile" = "x" ]; then
[19023]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
[18866]113 configfile="$GSDLHOME/llssite.cfg";
114 fi ;
[18851]115 echo "Configuring the apache webserver..." ;
[18866]116 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
[20619]117 hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;
[20603]118
[19250]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
[20619]126 echo -e "$port\n$hosts\n$externalaccess" | configure-port-and-connection ;
[18851]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
[18866]137 configure-apache $1
[18851]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
[20342]148 if [ $? = 0 ] ; then
149 echo $MONITOR_SUCCESS;
150 else
151 echo $MONITOR_FAILED;
152 fi
153 echo $MONITOR_FINISHED;
[18851]154}
155
156function web-restart {
157 test-gsdlhome
158 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart
[20342]159 if [ $? = 0 ] ; then
160 echo $MONITOR_SUCCESS;
161 else
162 echo $MONITOR_FAILED;
163 fi
164 echo $MONITOR_FINISHED;
[18851]165}
166
167function web-graceful {
168 test-gsdlhome
169 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful
[20342]170 if [ $? = 0 ] ; then
171 echo $MONITOR_SUCCESS;
172 else
173 echo $MONITOR_FAILED;
174 fi
175 echo $MONITOR_FINISHED;
[18851]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
[20342]191 if [ $? = 0 ] ; then
192 echo $MONITOR_SUCCESS;
193 else
194 echo $MONITOR_FAILED;
195 fi
196 echo $MONITOR_FINISHED;
[18851]197}
198
[19453]199function usage {
[18851]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"
[18866]209 echo " configure-web [config-filename]"
210 echo " configure-apache [config-filename]"
[18851]211 echo " configure-cgi"
212 echo " test-gsdlhome"
213 echo " web-stop-tested"
214 echo ""
[19453]215}
216
217
218if [[ $# < 1 || $# > 2 ]] ; then
219 usage
[18851]220 exit 0
221fi
222
223target=$1
[18866]224configfile=$2
[18851]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)
[18866]240 configure-web $configfile;;
[18851]241 configure-apache)
[18866]242 configure-apache $configfile;;
[18851]243 configure-cgi)
244 configure-cgi;;
[20619]245 set-port)
246 configure-port-and-connection;;
[18851]247 test-gsdlhome)
248 test-gsdlhome;;
249 web-stop-tested)
250 web-stop-tested;;
[19453]251 *)
252 echo
253 echo "Command unrecognised: $target"
254 usage;;
255
[18851]256esac
257
[19257]258exit;
Note: See TracBrowser for help on using the repository browser.