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