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

Last change on this file since 23945 was 23945, checked in by ak19, 13 years ago

First set of changes to the gsicontrol scripts to introduce the reset-gsdlhome flag. Still need to deal with the GSDLHOME placeholders in the Mac .app files and need to create their template .in files

  • Property svn:executable set to *
File size: 7.0 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 "Enter hostname or list of hosts to allow (localhost included by default):"
59 read hosts ;
60 echo "Allow external connections [yes/no]:"
61 read connection ;
62 if [ "x$connection" = "xyes" ] || [ "x$connection" = "xy" ] ; then
63 allowfromall="Allow"
64 else
65 allowfromall="Deny"
66 fi
67
68 lib_path_var="LD_LIBRARY_PATH" ;
69 if [ $GSDLOS = "darwin" ] ; then
70 lib_path_var="DYLD_LIBRARY_PATH"
71 fi
72
73 if test -e $GSDLHOME/cgi-bin/gsdlsite.cfg ; then
74 collecthome=`egrep "^collecthome" $GSDLHOME/cgi-bin/gsdlsite.cfg | awk '{print $2}'` ;
75 fi
76 if test -z $collecthome ; then
77 collecthome="$GSDLHOME/collect" ;
78 fi
79
80 if test ! -z $port ; then
81 echo "Port: $port" ;
82 echo "Stopping web server (if running)" ;
83 web-stop-tested ;
84 echo "Setting config file to use port $port";
85 cat "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf.in" \
86 | sed "s@\*\*PORT\*\*@$port@g" \
87 | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
88 | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
89 | sed "s@\*\*HOSTS\*\*@$hosts@g" \
90 | sed "s@\*\*COLLECTHOME\*\*@$collecthome@g" \
91 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
92 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS@g" \
93 | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@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
107 configfile=$1 ;
108# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
109 if [ "x$configfile" = "x" ]; then
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
113 configfile="$GSDLHOME/llssite.cfg";
114 fi ;
115 echo "Configuring the apache webserver..." ;
116 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
117 hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
118 hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;
119
120 externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
121 if [ "x$externalaccess" = "x1" ] ; then
122 externalaccess="yes"
123 else
124 externalaccess="no"
125 fi
126
127 echo -e "$port\n$hostIP\n$hosts\n$externalaccess" | configure-port-and-connection ;
128 if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
129 echo $MONITOR_SUCCESS;
130 else
131 echo $MONITOR_FAILED;
132 fi
133 echo $MONITOR_FINISHED
134}
135
136function configure-web {
137 configure-cgi
138 configure-apache $1
139}
140
141# forces configure-cgi by deleting gsdlsite.cfg
142function reset-gsdlhome {
143 if test -e "$GSDLHOME/cgi-bin/gsdlsite.cfg" ; then
144 echo "**** WARNING. Local changes made to $GSDLHOME/cgi-bin/gsdlsite.cfg will be lost.";
145 rm -f "$GSDLHOME/cgi-bin/gsdlsite.cfg";
146 fi
147 configure-web $1
148}
149
150function web-status {
151 test-gsdlhome
152 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl status
153}
154
155function web-start {
156 test-gsdlhome
157 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl start
158 if [ $? = 0 ] ; then
159 echo $MONITOR_SUCCESS;
160 else
161 echo $MONITOR_FAILED;
162 fi
163 echo $MONITOR_FINISHED;
164}
165
166function web-restart {
167 test-gsdlhome
168 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart
169 if [ $? = 0 ] ; then
170 echo $MONITOR_SUCCESS;
171 else
172 echo $MONITOR_FAILED;
173 fi
174 echo $MONITOR_FINISHED;
175}
176
177function web-graceful {
178 test-gsdlhome
179 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful
180 if [ $? = 0 ] ; then
181 echo $MONITOR_SUCCESS;
182 else
183 echo $MONITOR_FAILED;
184 fi
185 echo $MONITOR_FINISHED;
186}
187
188function web-stop-tested {
189# This version runs without testing for GSDLHOME
190# Useful to be run as a target when we know test-gsdlhome has already
191# been done. This avoids an unnecessary repetition of printing
192# out the values of GSDLHOME and GSDLOS
193 if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
194 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl stop ;
195 fi
196}
197
198function web-stop {
199 test-gsdlhome
200 web-stop-tested
201 if [ $? = 0 ] ; then
202 echo $MONITOR_SUCCESS;
203 else
204 echo $MONITOR_FAILED;
205 fi
206 echo $MONITOR_FINISHED;
207}
208
209function usage {
210 echo ""
211 echo " Usage: $0 <command>"
212 echo " where <command> is any of the following: "
213 echo " web-start"
214 echo " web-stop"
215 echo " web-restart"
216 echo " web-status"
217 echo " web-graceful"
218 echo " configure-admin"
219 echo " configure-web [config-filename]"
220 echo " configure-apache [config-filename]"
221 echo " configure-cgi"
222 echo " reset-gsdlhome [config-filename]\n\t(Save a copy of cgi-bin/gsdlsite.cfg to preserve any customisations)"
223 echo " test-gsdlhome"
224 echo " web-stop-tested"
225 echo ""
226}
227
228
229if [[ $# < 1 || $# > 2 ]] ; then
230 usage
231 exit 0
232fi
233
234target=$1
235configfile=$2
236
237# remove any extraneous double quotes
238configfile=${configfile//\"/}
239
240case $target in
241 web-start)
242 web-start;;
243 web-stop)
244 web-stop;;
245 web-restart)
246 web-restart;;
247 web-status)
248 web-status;;
249 web-graceful)
250 web-graceful;;
251 configure-admin)
252 configure-admin;;
253 configure-web)
254 configure-web $configfile;;
255 configure-apache)
256 configure-apache $configfile;;
257 configure-cgi)
258 configure-cgi;;
259 set-port)
260 configure-port-and-connection;;
261 reset-gsdlhome)
262 reset-gsdlhome;;
263 test-gsdlhome)
264 test-gsdlhome;;
265 web-stop-tested)
266 web-stop-tested;;
267 *)
268 echo
269 echo "Command unrecognised: $target"
270 usage;;
271
272esac
273
274exit;
Note: See TracBrowser for help on using the repository browser.