source: main/trunk/greenstone2/gsicontrol.sh@ 23134

Last change on this file since 23134 was 23134, checked in by davidb, 14 years ago

Couple of extra minor tweaks to prevent variables being tested that are undefined

  • Property svn:executable set to *
File size: 6.3 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 ;
[23134]60 if [ "x$connection" = "xyes" ] || [ "x$connection" = "xy" ] ; 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
[22635]71 if test -e $GSDLHOME/cgi-bin/gsdlsite.cfg ; then
72 collecthome=`egrep "^collecthome" $GSDLHOME/cgi-bin/gsdlsite.cfg | awk '{print $2}'` ;
73 fi
74 if test -z $collecthome ; then
75 collecthome="$GSDLHOME/collect" ;
76 fi
77
[18851]78 if test ! -z $port ; then
79 echo "Port: $port" ;
80 echo "Stopping web server (if running)" ;
81 web-stop-tested ;
82 echo "Setting config file to use port $port";
83 cat "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf.in" \
84 | sed "s@\*\*PORT\*\*@$port@g" \
[20619]85 | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
[20622]86 | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
[22635]87 | sed "s@\*\*COLLECTHOME\*\*@$collecthome@g" \
[18851]88 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
89 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS@g" \
[20829]90 | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
[18851]91 > "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ;
92 echo "Type '$0 web-start' to start the web server running on port $port" ;
93 fi ;
94 echo "Done" ;
95}
96
97
98MONITOR_SUCCESS="MAKE SUCCESSFUL"
99MONITOR_FAILED="MAKE FAILED"
100MONITOR_FINISHED="MAKE DONE"
101
102function configure-apache {
103 test-gsdlhome
[18866]104 configfile=$1 ;
[19023]105# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
[18866]106 if [ "x$configfile" = "x" ]; then
[19023]107 if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
108 cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
109 fi
[18866]110 configfile="$GSDLHOME/llssite.cfg";
111 fi ;
[18851]112 echo "Configuring the apache webserver..." ;
[18866]113 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
[20622]114 hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
[20603]115
[19250]116 externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
[23134]117 if [ "x$externalaccess" = "x1" ] ; then
[19250]118 externalaccess="yes"
119 else
120 externalaccess="no"
121 fi
122
[20622]123 echo -e "$port\n$hostIP\n$externalaccess" | configure-port-and-connection ;
[18851]124 if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
125 echo $MONITOR_SUCCESS;
126 else
127 echo $MONITOR_FAILED;
128 fi
129 echo $MONITOR_FINISHED
130}
131
132function configure-web {
133 configure-cgi
[18866]134 configure-apache $1
[18851]135}
136
137function web-status {
138 test-gsdlhome
139 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl status
140}
141
142function web-start {
143 test-gsdlhome
144 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl start
[20342]145 if [ $? = 0 ] ; then
146 echo $MONITOR_SUCCESS;
147 else
148 echo $MONITOR_FAILED;
149 fi
150 echo $MONITOR_FINISHED;
[18851]151}
152
153function web-restart {
154 test-gsdlhome
155 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart
[20342]156 if [ $? = 0 ] ; then
157 echo $MONITOR_SUCCESS;
158 else
159 echo $MONITOR_FAILED;
160 fi
161 echo $MONITOR_FINISHED;
[18851]162}
163
164function web-graceful {
165 test-gsdlhome
166 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful
[20342]167 if [ $? = 0 ] ; then
168 echo $MONITOR_SUCCESS;
169 else
170 echo $MONITOR_FAILED;
171 fi
172 echo $MONITOR_FINISHED;
[18851]173}
174
175function web-stop-tested {
176# This version runs without testing for GSDLHOME
177# Useful to be run as a target when we know test-gsdlhome has already
[20637]178# been done. This avoids an unnecessary repetition of printing
[18851]179# out the values of GSDLHOME and GSDLOS
180 if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
181 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl stop ;
182 fi
183}
184
185function web-stop {
186 test-gsdlhome
187 web-stop-tested
[20342]188 if [ $? = 0 ] ; then
189 echo $MONITOR_SUCCESS;
190 else
191 echo $MONITOR_FAILED;
192 fi
193 echo $MONITOR_FINISHED;
[18851]194}
195
[19453]196function usage {
[18851]197 echo ""
198 echo " Usage: $0 <command>"
199 echo " where <command> is any of the following: "
200 echo " web-start"
201 echo " web-stop"
202 echo " web-restart"
203 echo " web-status"
204 echo " web-graceful"
205 echo " configure-admin"
[18866]206 echo " configure-web [config-filename]"
207 echo " configure-apache [config-filename]"
[18851]208 echo " configure-cgi"
209 echo " test-gsdlhome"
210 echo " web-stop-tested"
211 echo ""
[19453]212}
213
214
215if [[ $# < 1 || $# > 2 ]] ; then
216 usage
[18851]217 exit 0
218fi
219
220target=$1
[18866]221configfile=$2
[18851]222
[20919]223# remove any extraneous double quotes
224configfile=${configfile//\"/}
225
[18851]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.