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

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

GSIControl.sh also needs to set (DY)LD_LIBRARY_PATH so that the Mac can find the libiconv(2).dylib that apache needs.

  • Property svn:executable set to *
File size: 7.3 KB
Line 
1#!/bin/bash
2
3testdone=0
4
5# Setup.bash needs to be sourced
6# On MAC, need to tell apache to find and use its own libiconv<num>.dylib
7# If gs2-server.sh is run from GLI, we can't just test for the existence
8# of "apache-httpd", so use the full path (from GSDLHOME) to test it exists
9function test-gsdlhome {
10 if [ $testdone == "0" ] ; then
11 if test -z "$GSDLHOME" ; then
12 echo "" ;
13 echo "Environment variable GSDLHOME not set." ;
14 echo " This needs to be set to run this gsicontrol command." ;
15 echo " Have you run 'source setup.bash'?" ;
16 echo "" ;
17 exit 1
18 else
19 echo "Using: " ;
20 echo " GSDLHOME = $GSDLHOME" ;
21 echo " GSDLOS = $GSDLOS" ;
22 if test -e "$GSDLHOME/apache-httpd" ; then
23 echo "+Adding in executable path for apache-httpd"
24 PATH=$GSDLHOME/apache-httpd/$GSDLOS/bin:$PATH
25 export PATH
26
27 if test "$GSDLOS" = "linux" ; then
28 LD_LIBRARY_PATH="$GSDLHOME/apache-httpd/$GSDLOS/lib:$LD_LIBRARY_PATH"
29 export LD_LIBRARY_PATH
30 elif test "$GSDLOS" = "darwin" ; then
31 DYLD_LIBRARY_PATH="$GSDLHOME/apache-httpd/$GSDLOS/lib:$DYLD_LIBRARY_PATH"
32 export DYLD_LIBRARY_PATH
33 fi
34 fi
35 fi
36 testdone=1
37 fi
38}
39
40function configure-cgi {
41 test-gsdlhome
42 if test ! -e $GSDLHOME/cgi-bin/gsdlsite.cfg ; then
43 echo "Configuring cgi-bin/gsdlsite.cfg" ;
44 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg ;
45 else
46 echo "WARNING: Nothing done for make configure-cgi." ;
47 echo " If you wish to regenerate the file " ;
48 echo " $GSDLHOME/cgi-bin/gsdlsite.cfg" ;
49 echo " from scratch, delete the existing file first." ;
50 fi
51}
52
53function configure-admin {
54 test-gsdlhome
55 echo "" ;
56 echo "Configuring admin user password:" ;
57 encrypted_password=`getpw` ;
58 if [ $? = "0" ] ; then
59 echo -e "[admin]\n<enabled>true\n<groups>administrator,colbuilder,all-collections-editor\n<password>$encrypted_password\n<username>admin" \
60 | txt2db -append "$GSDLHOME/etc/users.gdb" ;
61 else
62 echo "Did not set password" ;
63 fi
64 echo ""
65}
66
67
68function configure-port-and-connection {
69 test-gsdlhome
70
71 echo "Enter port number to use:"
72 read port ;
73 echo "Enter host IP to allow (127.0.0.1 is included by default):"
74 read hostIP ;
75 echo "Enter hostname or list of hosts to allow (localhost included by default):"
76 read hosts ;
77 echo "Allow external connections [yes/no]:"
78 read connection ;
79 if [ "x$connection" = "xyes" ] || [ "x$connection" = "xy" ] ; then
80 allowfromall="Allow"
81 else
82 allowfromall="Deny"
83 fi
84
85 lib_path_var="LD_LIBRARY_PATH" ;
86 if [ $GSDLOS = "darwin" ] ; then
87 lib_path_var="DYLD_LIBRARY_PATH"
88 fi
89
90 if test -e $GSDLHOME/cgi-bin/gsdlsite.cfg ; then
91 collecthome=`egrep "^collecthome" $GSDLHOME/cgi-bin/gsdlsite.cfg | awk '{print $2}'` ;
92 fi
93 if test -z $collecthome ; then
94 collecthome="$GSDLHOME/collect" ;
95 fi
96
97 if test ! -z $port ; then
98 echo "Port: $port" ;
99 echo "Stopping web server (if running)" ;
100 web-stop-tested ;
101 echo "Setting config file to use port $port";
102 cat "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf.in" \
103 | sed "s@\*\*PORT\*\*@$port@g" \
104 | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
105 | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
106 | sed "s@\*\*HOSTS\*\*@$hosts@g" \
107 | sed "s@\*\*COLLECTHOME\*\*@$collecthome@g" \
108 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
109 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS@g" \
110 | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
111 > "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ;
112 echo "Type '$0 web-start' to start the web server running on port $port" ;
113 fi ;
114 echo "Done" ;
115}
116
117
118MONITOR_SUCCESS="MAKE SUCCESSFUL"
119MONITOR_FAILED="MAKE FAILED"
120MONITOR_FINISHED="MAKE DONE"
121
122function configure-apache {
123 test-gsdlhome
124 configfile=$1 ;
125# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
126 if [ "x$configfile" = "x" ]; then
127 if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
128 cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
129 fi
130 configfile="$GSDLHOME/llssite.cfg";
131 fi ;
132 echo "Configuring the apache webserver..." ;
133 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
134 hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
135 hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;
136
137 externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
138 if [ "x$externalaccess" = "x1" ] ; then
139 externalaccess="yes"
140 else
141 externalaccess="no"
142 fi
143
144 echo -e "$port\n$hostIP\n$hosts\n$externalaccess" | configure-port-and-connection ;
145 if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
146 echo $MONITOR_SUCCESS;
147 else
148 echo $MONITOR_FAILED;
149 fi
150 echo $MONITOR_FINISHED
151}
152
153function configure-web {
154 configure-cgi
155 configure-apache $1
156}
157
158function web-status {
159 test-gsdlhome
160 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl status
161}
162
163function web-start {
164 test-gsdlhome
165 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl start
166 if [ $? = 0 ] ; then
167 echo $MONITOR_SUCCESS;
168 else
169 echo $MONITOR_FAILED;
170 fi
171 echo $MONITOR_FINISHED;
172}
173
174function web-restart {
175 test-gsdlhome
176 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart
177 if [ $? = 0 ] ; then
178 echo $MONITOR_SUCCESS;
179 else
180 echo $MONITOR_FAILED;
181 fi
182 echo $MONITOR_FINISHED;
183}
184
185function web-graceful {
186 test-gsdlhome
187 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful
188 if [ $? = 0 ] ; then
189 echo $MONITOR_SUCCESS;
190 else
191 echo $MONITOR_FAILED;
192 fi
193 echo $MONITOR_FINISHED;
194}
195
196function web-stop-tested {
197# This version runs without testing for GSDLHOME
198# Useful to be run as a target when we know test-gsdlhome has already
199# been done. This avoids an unnecessary repetition of printing
200# out the values of GSDLHOME and GSDLOS
201 if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
202 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl stop ;
203 fi
204}
205
206function web-stop {
207 test-gsdlhome
208 web-stop-tested
209 if [ $? = 0 ] ; then
210 echo $MONITOR_SUCCESS;
211 else
212 echo $MONITOR_FAILED;
213 fi
214 echo $MONITOR_FINISHED;
215}
216
217function usage {
218 echo ""
219 echo " Usage: $0 <command>"
220 echo " where <command> is any of the following: "
221 echo " web-start"
222 echo " web-stop"
223 echo " web-restart"
224 echo " web-status"
225 echo " web-graceful"
226 echo " configure-admin"
227 echo " configure-web [config-filename]"
228 echo " configure-apache [config-filename]"
229 echo " configure-cgi"
230 echo " test-gsdlhome"
231 echo " web-stop-tested"
232 echo ""
233}
234
235
236if [[ $# < 1 || $# > 2 ]] ; then
237 usage
238 exit 0
239fi
240
241target=$1
242configfile=$2
243
244# remove any extraneous double quotes
245configfile=${configfile//\"/}
246
247case $target in
248 web-start)
249 web-start;;
250 web-stop)
251 web-stop;;
252 web-restart)
253 web-restart;;
254 web-status)
255 web-status;;
256 web-graceful)
257 web-graceful;;
258 configure-admin)
259 configure-admin;;
260 configure-web)
261 configure-web $configfile;;
262 configure-apache)
263 configure-apache $configfile;;
264 configure-cgi)
265 configure-cgi;;
266 set-port)
267 configure-port-and-connection;;
268 test-gsdlhome)
269 test-gsdlhome;;
270 web-stop-tested)
271 web-stop-tested;;
272 *)
273 echo
274 echo "Command unrecognised: $target"
275 usage;;
276
277esac
278
279exit;
Note: See TracBrowser for help on using the repository browser.