source: gsdl/trunk/gsicontrol.sh@ 20973

Last change on this file since 20973 was 20919, checked in by ak19, 14 years ago

Changes to previous commits (to handle spaces in filepaths on Windows) so that things still work on Linux: removes any extra quotes around configfile

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