1 | #!/bin/bash
|
---|
2 |
|
---|
3 | storedir="`pwd`"
|
---|
4 | thisdir="`dirname \"$0\"`"
|
---|
5 | thisdir="`cd \"$thisdir\" && pwd`"
|
---|
6 | cd "$thisdir"
|
---|
7 | source setup.bash
|
---|
8 |
|
---|
9 | testdone=0
|
---|
10 |
|
---|
11 | cgibin="cgi-bin"
|
---|
12 | if [ -d "cgi-bin/$GSDLOS$GSDLARCH" ] ; then
|
---|
13 | cgibin="cgi-bin/$GSDLOS$GSDLARCH"
|
---|
14 | fi
|
---|
15 |
|
---|
16 |
|
---|
17 | function test-gsdlhome {
|
---|
18 | if [ $testdone == "0" ] ; then
|
---|
19 | if test -z "$GSDLHOME" ; then
|
---|
20 | echo "" ;
|
---|
21 | echo "Environment variable GSDLHOME not set." ;
|
---|
22 | echo " This needs to be set to run this gsicontrol command." ;
|
---|
23 | echo " Have you run 'source setup.bash'?" ;
|
---|
24 | echo "" ;
|
---|
25 | exit 1
|
---|
26 | else
|
---|
27 | echo "Using: " ;
|
---|
28 | echo " GSDLHOME = $GSDLHOME" ;
|
---|
29 | echo " GSDLOS = $GSDLOS" ;
|
---|
30 | fi
|
---|
31 | testdone=1
|
---|
32 | fi
|
---|
33 | }
|
---|
34 |
|
---|
35 | function configure-cgi {
|
---|
36 | test-gsdlhome
|
---|
37 | if test ! -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
|
---|
38 | echo "Configuring $cgibin/gsdlsite.cfg" ;
|
---|
39 | echo "# **** This file is automatically generated, do not edit ****" > "$cgibin/gsdlsite.cfg" ;
|
---|
40 | echo "# For local customization of Greenstone, edit gsdlsite.cfg.in" >> "$cgibin/gsdlsite.cfg" ;
|
---|
41 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "$cgibin/gsdlsite.cfg.in" >> "$cgibin/gsdlsite.cfg" ;
|
---|
42 | else
|
---|
43 | echo "WARNING: Nothing done for make configure-cgi." ;
|
---|
44 | echo " If you wish to regenerate the file " ;
|
---|
45 | echo " $GSDLHOME/$cgibin/gsdlsite.cfg" ;
|
---|
46 | echo " from scratch, delete the existing file first." ;
|
---|
47 | fi
|
---|
48 | }
|
---|
49 |
|
---|
50 | function configure-admin {
|
---|
51 | test-gsdlhome
|
---|
52 | echo "" ;
|
---|
53 | echo "Configuring admin user password:" ;
|
---|
54 | encrypted_password=`getpw` ;
|
---|
55 | if [ $? = "0" ] ; then
|
---|
56 | echo -e "[admin]\n<enabled>true\n<groups>administrator,colbuilder,all-collections-editor\n<password>$encrypted_password\n<username>admin" \
|
---|
57 | | txt2db -append "$GSDLHOME/etc/users.gdb" ;
|
---|
58 | else
|
---|
59 | echo "Did not set password" ;
|
---|
60 | fi
|
---|
61 | echo ""
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | function configure-port-and-connection {
|
---|
66 | test-gsdlhome
|
---|
67 |
|
---|
68 | echo "Enter port number to use:"
|
---|
69 | read port ;
|
---|
70 | echo "Enter host IP to allow (127.0.0.1 is included by default):"
|
---|
71 | read hostIP ;
|
---|
72 | echo "Enter hostname or list of hosts to allow (localhost included by default):"
|
---|
73 | read hosts ;
|
---|
74 | echo "Allow external connections [yes/no]:"
|
---|
75 | read connection ;
|
---|
76 | if [ "x$connection" = "xyes" ] || [ "x$connection" = "xy" ] ; then
|
---|
77 | allowfromall="Allow"
|
---|
78 | else
|
---|
79 | allowfromall="Deny"
|
---|
80 | fi
|
---|
81 |
|
---|
82 | lib_path_var="LD_LIBRARY_PATH" ;
|
---|
83 | if [ $GSDLOS = "darwin" ] ; then
|
---|
84 | lib_path_var="DYLD_LIBRARY_PATH"
|
---|
85 | fi
|
---|
86 |
|
---|
87 | if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
|
---|
88 | collecthome=`egrep "^collecthome" "$GSDLHOME/$cgibin/gsdlsite.cfg" | awk '{print $2}'` ;
|
---|
89 | fi
|
---|
90 | if test -z $collecthome ; then
|
---|
91 | collecthome="$GSDLHOME/collect" ;
|
---|
92 | fi
|
---|
93 |
|
---|
94 | if test ! -z $port ; then
|
---|
95 | echo "Port: $port" ;
|
---|
96 | echo "Stopping web server (if running)" ;
|
---|
97 | web-stop-tested ;
|
---|
98 | echo "Setting config file to use port $port";
|
---|
99 | cat "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf.in" \
|
---|
100 | | sed "s@\*\*PORT\*\*@$port@g" \
|
---|
101 | | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
|
---|
102 | | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
|
---|
103 | | sed "s@\*\*HOSTS\*\*@$hosts@g" \
|
---|
104 | | sed "s@\*\*COLLECTHOME\*\*@$collecthome@g" \
|
---|
105 | | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
|
---|
106 | | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH@g" \
|
---|
107 | | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
|
---|
108 | > "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ;
|
---|
109 | echo "Type '$0 web-start' to start the web server running on port $port" ;
|
---|
110 | fi ;
|
---|
111 | echo "Done" ;
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 | MONITOR_SUCCESS="MAKE SUCCESSFUL"
|
---|
116 | MONITOR_FAILED="MAKE FAILED"
|
---|
117 | MONITOR_FINISHED="MAKE DONE"
|
---|
118 |
|
---|
119 | function configure-apache {
|
---|
120 | test-gsdlhome
|
---|
121 | configfile=$1 ;
|
---|
122 | # if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
|
---|
123 | if [ "x$configfile" = "x" ]; then
|
---|
124 | if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
|
---|
125 | cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
|
---|
126 | fi
|
---|
127 | configfile="$GSDLHOME/llssite.cfg";
|
---|
128 | fi ;
|
---|
129 | echo "Configuring the apache webserver..." ;
|
---|
130 | port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
|
---|
131 | hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
|
---|
132 | hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;
|
---|
133 |
|
---|
134 | externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
|
---|
135 | if [ "x$externalaccess" = "x1" ] ; then
|
---|
136 | externalaccess="yes"
|
---|
137 | else
|
---|
138 | externalaccess="no"
|
---|
139 | fi
|
---|
140 |
|
---|
141 | echo -e "$port\n$hostIP\n$hosts\n$externalaccess" | configure-port-and-connection ;
|
---|
142 | if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
|
---|
143 | echo $MONITOR_SUCCESS;
|
---|
144 | else
|
---|
145 | echo $MONITOR_FAILED;
|
---|
146 | fi
|
---|
147 | echo $MONITOR_FINISHED
|
---|
148 | }
|
---|
149 |
|
---|
150 | function configure-web {
|
---|
151 | for one_file in gs2-server.app gli.app client-gli.app gems.app ; do
|
---|
152 | if test ! -e "$one_file/Contents/document.wflow" ; then
|
---|
153 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "$one_file/Contents/document.wflow.in" > "$one_file/Contents/document.wflow"
|
---|
154 | fi
|
---|
155 | done ;
|
---|
156 |
|
---|
157 | configure-cgi
|
---|
158 | configure-apache $1
|
---|
159 | }
|
---|
160 |
|
---|
161 | # forces configure-cgi by deleting gsdlsite.cfg
|
---|
162 | function reset-gsdlhome {
|
---|
163 | echo "" ;
|
---|
164 | if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
|
---|
165 | /bin/mv "$GSDLHOME/$cgibin/gsdlsite.cfg" "$GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
|
---|
166 | echo "**** Regenerating $GSDLHOME/$cgibin/gsdlsite.cfg" ;
|
---|
167 | echo "**** Previous version of file now $GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
|
---|
168 | fi
|
---|
169 |
|
---|
170 | apache_home_os="$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH"
|
---|
171 |
|
---|
172 | if test ! -e "$apache_home_os/bin/apachectl.in" ; then
|
---|
173 | make apache-for-dist
|
---|
174 | fi
|
---|
175 |
|
---|
176 | replace_list="conf/extra/httpd-dav.conf \
|
---|
177 | conf/extra/httpd-manual.conf \
|
---|
178 | conf/extra/httpd-autoindex.conf \
|
---|
179 | conf/extra/httpd-vhosts.conf \
|
---|
180 | conf/extra/httpd-ssl.conf \
|
---|
181 | conf/extra/httpd-multilang-errordoc.conf \
|
---|
182 | conf/original/extra/httpd-dav.conf \
|
---|
183 | conf/original/extra/httpd-manual.conf \
|
---|
184 | conf/original/extra/httpd-autoindex.conf \
|
---|
185 | conf/original/extra/httpd-vhosts.conf \
|
---|
186 | conf/original/extra/httpd-ssl.conf \
|
---|
187 | conf/original/extra/httpd-multilang-errordoc.conf \
|
---|
188 | conf/original/httpd.conf\
|
---|
189 | lib/apr-util-1/apr_dbd_odbc.la \
|
---|
190 | lib/apr-util-1/apr_dbd_sqlite3.la \
|
---|
191 | lib/pkgconfig/apr-util-1.pc \
|
---|
192 | lib/pkgconfig/apr-1.pc \
|
---|
193 | lib/libaprutil-1.la \
|
---|
194 | lib/libapr-1.la \
|
---|
195 | build/config_vars.mk \
|
---|
196 | build/config.nice \
|
---|
197 | build/apr_rules.mk \
|
---|
198 | bin/dbmmanage \
|
---|
199 | bin/apu-1-config \
|
---|
200 | bin/apr-1-config \
|
---|
201 | include/ap_config_auto.h \
|
---|
202 | include/ap_config_layout.h"
|
---|
203 |
|
---|
204 | for one_file in apachectl envvars envvars-std ; do
|
---|
205 | /bin/cp "$apache_home_os/bin/$one_file.in" "$apache_home_os/bin/$one_file"
|
---|
206 | done
|
---|
207 |
|
---|
208 | for one_file in $replace_list ; do
|
---|
209 | /bin/cp "$apache_home_os/$one_file.in" "$apache_home_os/$one_file"
|
---|
210 | done
|
---|
211 |
|
---|
212 | /bin/cp "$apache_home_os/bin/apr-1-config.in" "$apache_home_os/bin/apr-1-config"
|
---|
213 |
|
---|
214 | /bin/cp "$apache_home_os/bin/apu-1-config.in" "$apache_home_os/bin/apu-1-config"
|
---|
215 |
|
---|
216 | /bin/cp "$apache_home_os/build/config_vars.mk.in" "$apache_home_os/build/config_vars.mk"
|
---|
217 |
|
---|
218 | bash "$apache_home_os/install-bindist.sh" "$apache_home_os"
|
---|
219 |
|
---|
220 | log4jprop=$GSDLHOME/lib/java/log4j.properties
|
---|
221 | sed "s^@gsdl2home@^$GSDLHOME^g" "$log4jprop.in" > "$log4jprop"
|
---|
222 |
|
---|
223 | for one_file in gs2-server.app gli.app client-gli.app gems.app ; do
|
---|
224 | if test -e "$one_file/Contents/document.wflow" ; then
|
---|
225 | rm -f "$one_file/Contents/document.wflow"
|
---|
226 | fi
|
---|
227 | done
|
---|
228 |
|
---|
229 | configure-web $1
|
---|
230 | }
|
---|
231 |
|
---|
232 | function web-status {
|
---|
233 | test-gsdlhome
|
---|
234 | $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl status
|
---|
235 | }
|
---|
236 |
|
---|
237 | function web-start {
|
---|
238 | test-gsdlhome
|
---|
239 | $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl start
|
---|
240 | if [ $? = 0 ] ; then
|
---|
241 | echo $MONITOR_SUCCESS;
|
---|
242 | else
|
---|
243 | echo $MONITOR_FAILED;
|
---|
244 | fi
|
---|
245 | echo $MONITOR_FINISHED;
|
---|
246 | }
|
---|
247 |
|
---|
248 | function web-restart {
|
---|
249 | test-gsdlhome
|
---|
250 | $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl restart
|
---|
251 | if [ $? = 0 ] ; then
|
---|
252 | echo $MONITOR_SUCCESS;
|
---|
253 | else
|
---|
254 | echo $MONITOR_FAILED;
|
---|
255 | fi
|
---|
256 | echo $MONITOR_FINISHED;
|
---|
257 | }
|
---|
258 |
|
---|
259 | function web-graceful {
|
---|
260 | test-gsdlhome
|
---|
261 | $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl graceful
|
---|
262 | if [ $? = 0 ] ; then
|
---|
263 | echo $MONITOR_SUCCESS;
|
---|
264 | else
|
---|
265 | echo $MONITOR_FAILED;
|
---|
266 | fi
|
---|
267 | echo $MONITOR_FINISHED;
|
---|
268 | }
|
---|
269 |
|
---|
270 | function web-stop-tested {
|
---|
271 | # This version runs without testing for GSDLHOME
|
---|
272 | # Useful to be run as a target when we know test-gsdlhome has already
|
---|
273 | # been done. This avoids an unnecessary repetition of printing
|
---|
274 | # out the values of GSDLHOME and GSDLOS
|
---|
275 | if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
|
---|
276 | $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl stop ;
|
---|
277 | fi
|
---|
278 | }
|
---|
279 |
|
---|
280 | function web-stop {
|
---|
281 | test-gsdlhome
|
---|
282 | web-stop-tested
|
---|
283 | if [ $? = 0 ] ; then
|
---|
284 | echo $MONITOR_SUCCESS;
|
---|
285 | else
|
---|
286 | echo $MONITOR_FAILED;
|
---|
287 | fi
|
---|
288 | echo $MONITOR_FINISHED;
|
---|
289 | }
|
---|
290 |
|
---|
291 | function usage {
|
---|
292 | echo ""
|
---|
293 | echo " Usage: $0 <command>"
|
---|
294 | echo " where <command> is any of the following: "
|
---|
295 | echo " web-start"
|
---|
296 | echo " web-stop"
|
---|
297 | echo " web-restart"
|
---|
298 | echo " web-status"
|
---|
299 | echo " web-graceful"
|
---|
300 | echo " configure-admin"
|
---|
301 | echo " configure-web [config-filename]"
|
---|
302 | echo " configure-apache [config-filename]"
|
---|
303 | echo " configure-cgi"
|
---|
304 | echo " reset-gsdlhome [config-filename]\n\t(Save a copy of $cgibin/gsdlsite.cfg to preserve any customisations)"
|
---|
305 | echo " test-gsdlhome"
|
---|
306 | echo " web-stop-tested"
|
---|
307 | echo ""
|
---|
308 | }
|
---|
309 |
|
---|
310 |
|
---|
311 | if [[ $# < 1 || $# > 2 ]] ; then
|
---|
312 | usage
|
---|
313 | exit 0
|
---|
314 | fi
|
---|
315 |
|
---|
316 | target=$1
|
---|
317 | configfile=$2
|
---|
318 |
|
---|
319 | # remove any extraneous double quotes
|
---|
320 | configfile=${configfile//\"/}
|
---|
321 |
|
---|
322 | case $target in
|
---|
323 | web-start)
|
---|
324 | web-start;;
|
---|
325 | web-stop)
|
---|
326 | web-stop;;
|
---|
327 | web-restart)
|
---|
328 | web-restart;;
|
---|
329 | web-status)
|
---|
330 | web-status;;
|
---|
331 | web-graceful)
|
---|
332 | web-graceful;;
|
---|
333 | configure-admin)
|
---|
334 | configure-admin;;
|
---|
335 | configure-web)
|
---|
336 | configure-web $configfile;;
|
---|
337 | configure-apache)
|
---|
338 | configure-apache $configfile;;
|
---|
339 | configure-cgi)
|
---|
340 | configure-cgi;;
|
---|
341 | set-port)
|
---|
342 | configure-port-and-connection;;
|
---|
343 | reset-gsdlhome)
|
---|
344 | reset-gsdlhome;;
|
---|
345 | test-gsdlhome)
|
---|
346 | test-gsdlhome;;
|
---|
347 | web-stop-tested)
|
---|
348 | web-stop-tested;;
|
---|
349 | *)
|
---|
350 | echo
|
---|
351 | echo "Command unrecognised: $target"
|
---|
352 | usage;;
|
---|
353 |
|
---|
354 | esac
|
---|
355 |
|
---|
356 | # jump back to directory we originally got called from
|
---|
357 | cd "$storedir"
|
---|
358 | exit;
|
---|