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

Last change on this file since 22635 was 22635, checked in by ak19, 14 years ago

3rd commit to do with having a relocatable collect dir. Changes to linux script and conf file (windows already changed in 2nd commit): Apache-httpd's conf file needs to have a collecthome alias section. GSI-control.sh writes in the value taken from gsdlsite.cfg.

  • Property svn:executable set to *
File size: 6.3 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 -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
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" \
85 | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
86 | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
87 | sed "s@\*\*COLLECTHOME\*\*@$collecthome@g" \
88 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
89 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS@g" \
90 | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
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
104 configfile=$1 ;
105# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
106 if [ "x$configfile" = "x" ]; then
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
110 configfile="$GSDLHOME/llssite.cfg";
111 fi ;
112 echo "Configuring the apache webserver..." ;
113 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
114 hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
115
116 externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
117 if [ $externalaccess == "1" ] ; then
118 externalaccess="yes"
119 else
120 externalaccess="no"
121 fi
122
123 echo -e "$port\n$hostIP\n$externalaccess" | configure-port-and-connection ;
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
134 configure-apache $1
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
145 if [ $? = 0 ] ; then
146 echo $MONITOR_SUCCESS;
147 else
148 echo $MONITOR_FAILED;
149 fi
150 echo $MONITOR_FINISHED;
151}
152
153function web-restart {
154 test-gsdlhome
155 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart
156 if [ $? = 0 ] ; then
157 echo $MONITOR_SUCCESS;
158 else
159 echo $MONITOR_FAILED;
160 fi
161 echo $MONITOR_FINISHED;
162}
163
164function web-graceful {
165 test-gsdlhome
166 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful
167 if [ $? = 0 ] ; then
168 echo $MONITOR_SUCCESS;
169 else
170 echo $MONITOR_FAILED;
171 fi
172 echo $MONITOR_FINISHED;
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
178# been done. This avoids an unnecessary repetition of printing
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
188 if [ $? = 0 ] ; then
189 echo $MONITOR_SUCCESS;
190 else
191 echo $MONITOR_FAILED;
192 fi
193 echo $MONITOR_FINISHED;
194}
195
196function usage {
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"
206 echo " configure-web [config-filename]"
207 echo " configure-apache [config-filename]"
208 echo " configure-cgi"
209 echo " test-gsdlhome"
210 echo " web-stop-tested"
211 echo ""
212}
213
214
215if [[ $# < 1 || $# > 2 ]] ; then
216 usage
217 exit 0
218fi
219
220target=$1
221configfile=$2
222
223# remove any extraneous double quotes
224configfile=${configfile//\"/}
225
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)
240 configure-web $configfile;;
241 configure-apache)
242 configure-apache $configfile;;
243 configure-cgi)
244 configure-cgi;;
245 set-port)
246 configure-port-and-connection;;
247 test-gsdlhome)
248 test-gsdlhome;;
249 web-stop-tested)
250 web-stop-tested;;
251 *)
252 echo
253 echo "Command unrecognised: $target"
254 usage;;
255
256esac
257
258exit;
Note: See TracBrowser for help on using the repository browser.