1 | #!/bin/bash
|
---|
2 |
|
---|
3 | testdone=0
|
---|
4 |
|
---|
5 | function 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 |
|
---|
23 | function 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 |
|
---|
36 | function 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 |
|
---|
51 | function 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 |
|
---|
90 | MONITOR_SUCCESS="MAKE SUCCESSFUL"
|
---|
91 | MONITOR_FAILED="MAKE FAILED"
|
---|
92 | MONITOR_FINISHED="MAKE DONE"
|
---|
93 |
|
---|
94 | function 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 |
|
---|
124 | function configure-web {
|
---|
125 | configure-cgi
|
---|
126 | configure-apache $1
|
---|
127 | }
|
---|
128 |
|
---|
129 | function web-status {
|
---|
130 | test-gsdlhome
|
---|
131 | $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl status
|
---|
132 | }
|
---|
133 |
|
---|
134 | function 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 |
|
---|
145 | function 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 |
|
---|
156 | function 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 |
|
---|
167 | function 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 |
|
---|
177 | function 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 |
|
---|
188 | function 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 |
|
---|
207 | if [[ $# < 1 || $# > 2 ]] ; then
|
---|
208 | usage
|
---|
209 | exit 0
|
---|
210 | fi
|
---|
211 |
|
---|
212 | target=$1
|
---|
213 | configfile=$2
|
---|
214 |
|
---|
215 | case $target in
|
---|
216 | web-start)
|
---|
217 | web-start;;
|
---|
218 | web-stop)
|
---|
219 | web-stop;;
|
---|
220 | web-restart)
|
---|
221 | web-restart;;
|
---|
222 | web-status)
|
---|
223 | web-status;;
|
---|
224 | web-graceful)
|
---|
225 | web-graceful;;
|
---|
226 | configure-admin)
|
---|
227 | configure-admin;;
|
---|
228 | configure-web)
|
---|
229 | configure-web $configfile;;
|
---|
230 | configure-apache)
|
---|
231 | configure-apache $configfile;;
|
---|
232 | configure-cgi)
|
---|
233 | configure-cgi;;
|
---|
234 | set-port)
|
---|
235 | configure-port-and-connection;;
|
---|
236 | test-gsdlhome)
|
---|
237 | test-gsdlhome;;
|
---|
238 | web-stop-tested)
|
---|
239 | web-stop-tested;;
|
---|
240 | *)
|
---|
241 | echo
|
---|
242 | echo "Command unrecognised: $target"
|
---|
243 | usage;;
|
---|
244 |
|
---|
245 | esac
|
---|
246 |
|
---|
247 | exit;
|
---|