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

Last change on this file since 21308 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
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 lib_path_var="LD_LIBRARY_PATH" ;
67 if [ $GSDLOS = "darwin" ] ; then
68 lib_path_var="DYLD_LIBRARY_PATH"
69 fi
70
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" \
78 | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
79 | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
80 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
81 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS@g" \
82 | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
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
96 configfile=$1 ;
97# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
98 if [ "x$configfile" = "x" ]; then
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
102 configfile="$GSDLHOME/llssite.cfg";
103 fi ;
104 echo "Configuring the apache webserver..." ;
105 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
106 hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
107
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
115 echo -e "$port\n$hostIP\n$externalaccess" | configure-port-and-connection ;
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
126 configure-apache $1
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
137 if [ $? = 0 ] ; then
138 echo $MONITOR_SUCCESS;
139 else
140 echo $MONITOR_FAILED;
141 fi
142 echo $MONITOR_FINISHED;
143}
144
145function web-restart {
146 test-gsdlhome
147 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart
148 if [ $? = 0 ] ; then
149 echo $MONITOR_SUCCESS;
150 else
151 echo $MONITOR_FAILED;
152 fi
153 echo $MONITOR_FINISHED;
154}
155
156function web-graceful {
157 test-gsdlhome
158 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful
159 if [ $? = 0 ] ; then
160 echo $MONITOR_SUCCESS;
161 else
162 echo $MONITOR_FAILED;
163 fi
164 echo $MONITOR_FINISHED;
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
170# been done. This avoids an unnecessary repetition of printing
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
180 if [ $? = 0 ] ; then
181 echo $MONITOR_SUCCESS;
182 else
183 echo $MONITOR_FAILED;
184 fi
185 echo $MONITOR_FINISHED;
186}
187
188function usage {
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"
198 echo " configure-web [config-filename]"
199 echo " configure-apache [config-filename]"
200 echo " configure-cgi"
201 echo " test-gsdlhome"
202 echo " web-stop-tested"
203 echo ""
204}
205
206
207if [[ $# < 1 || $# > 2 ]] ; then
208 usage
209 exit 0
210fi
211
212target=$1
213configfile=$2
214
215# remove any extraneous double quotes
216configfile=${configfile//\"/}
217
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)
232 configure-web $configfile;;
233 configure-apache)
234 configure-apache $configfile;;
235 configure-cgi)
236 configure-cgi;;
237 set-port)
238 configure-port-and-connection;;
239 test-gsdlhome)
240 test-gsdlhome;;
241 web-stop-tested)
242 web-stop-tested;;
243 *)
244 echo
245 echo "Command unrecognised: $target"
246 usage;;
247
248esac
249
250exit;
Note: See TracBrowser for help on using the repository browser.