#!/bin/bash testdone=0 cgibin="cgi-bin" if [ -d "cgi-bin/$GSDLOS$GSDLARCH" ] ; then cgibin="cgi-bin/$GSDLOS$GSDLARCH" fi function test-gsdlhome { if [ $testdone == "0" ] ; then if test -z "$GSDLHOME" ; then echo "" ; echo "Environment variable GSDLHOME not set." ; echo " This needs to be set to run this gsicontrol command." ; echo " Have you run 'source setup.bash'?" ; echo "" ; exit 1 else echo "Using: " ; echo " GSDLHOME = $GSDLHOME" ; echo " GSDLOS = $GSDLOS" ; fi testdone=1 fi } function configure-cgi { test-gsdlhome if test ! -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then echo "Configuring $cgibin/gsdlsite.cfg" ; sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "$cgibin/gsdlsite.cfg.in" > "$cgibin/gsdlsite.cfg" ; else echo "WARNING: Nothing done for make configure-cgi." ; echo " If you wish to regenerate the file " ; echo " $GSDLHOME/$cgibin/gsdlsite.cfg" ; echo " from scratch, delete the existing file first." ; fi } function configure-admin { test-gsdlhome echo "" ; echo "Configuring admin user password:" ; encrypted_password=`getpw` ; if [ $? = "0" ] ; then echo -e "[admin]\ntrue\nadministrator,colbuilder,all-collections-editor\n$encrypted_password\nadmin" \ | txt2db -append "$GSDLHOME/etc/users.gdb" ; else echo "Did not set password" ; fi echo "" } function configure-port-and-connection { test-gsdlhome echo "Enter port number to use:" read port ; echo "Enter host IP to allow (127.0.0.1 is included by default):" read hostIP ; echo "Enter hostname or list of hosts to allow (localhost included by default):" read hosts ; echo "Allow external connections [yes/no]:" read connection ; if [ "x$connection" = "xyes" ] || [ "x$connection" = "xy" ] ; then allowfromall="Allow" else allowfromall="Deny" fi lib_path_var="LD_LIBRARY_PATH" ; if [ $GSDLOS = "darwin" ] ; then lib_path_var="DYLD_LIBRARY_PATH" fi if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then collecthome=`egrep "^collecthome" "$GSDLHOME/$cgibin/gsdlsite.cfg" | awk '{print $2}'` ; fi if test -z $collecthome ; then collecthome="$GSDLHOME/collect" ; fi if test ! -z $port ; then echo "Port: $port" ; echo "Stopping web server (if running)" ; web-stop-tested ; echo "Setting config file to use port $port"; cat "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf.in" \ | sed "s@\*\*PORT\*\*@$port@g" \ | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \ | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \ | sed "s@\*\*HOSTS\*\*@$hosts@g" \ | sed "s@\*\*COLLECTHOME\*\*@$collecthome@g" \ | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \ | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH@g" \ | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \ > "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; echo "Type '$0 web-start' to start the web server running on port $port" ; fi ; echo "Done" ; } MONITOR_SUCCESS="MAKE SUCCESSFUL" MONITOR_FAILED="MAKE FAILED" MONITOR_FINISHED="MAKE DONE" function configure-apache { test-gsdlhome configfile=$1 ; # if no configfile given, launch it with llssite.cfg. Create it from the template if needed. if [ "x$configfile" = "x" ]; then if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ; fi configfile="$GSDLHOME/llssite.cfg"; fi ; echo "Configuring the apache webserver..." ; port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ; hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ; hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ; externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ; if [ "x$externalaccess" = "x1" ] ; then externalaccess="yes" else externalaccess="no" fi echo -e "$port\n$hostIP\n$hosts\n$externalaccess" | configure-port-and-connection ; if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then echo $MONITOR_SUCCESS; else echo $MONITOR_FAILED; fi echo $MONITOR_FINISHED } function configure-web { configure-cgi configure-apache $1 } # forces configure-cgi by deleting gsdlsite.cfg function reset-gsdlhome { echo "" ; if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then /bin/mv "$GSDLHOME/$cgibin/gsdlsite.cfg" "$GSDLHOME/$cgibin/gsdlsite.cfg.bak" ; echo "**** Regenerating $GSDLHOME/$cgibin/gsdlsite.cfg" ; echo "**** Previous version of file now $GSDLHOME/$cgibin/gsdlsite.cfg.bak" ; fi log4jprop=$GSDLHOME/lib/java/log4j.properties sed "s^@gsdl2home@^$GSDLHOME^g" "$log4jprop.in" > "$log4jprop" sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "gs2-server.app/Contents/document.wflow.in" > "gs2-server.app/Contents/document.wflow" sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "gli.app/Contents/document.wflow.in" > "gli.app/Contents/document.wflow" sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "client-gli.app/Contents/document.wflow.in" > "client-gli.app/Contents/document.wflow" sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "gems.app/Contents/document.wflow.in" > "gems.app/Contents/document.wflow" configure-web $1 } function web-status { test-gsdlhome $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl status } function web-start { test-gsdlhome $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl start if [ $? = 0 ] ; then echo $MONITOR_SUCCESS; else echo $MONITOR_FAILED; fi echo $MONITOR_FINISHED; } function web-restart { test-gsdlhome $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl restart if [ $? = 0 ] ; then echo $MONITOR_SUCCESS; else echo $MONITOR_FAILED; fi echo $MONITOR_FINISHED; } function web-graceful { test-gsdlhome $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl graceful if [ $? = 0 ] ; then echo $MONITOR_SUCCESS; else echo $MONITOR_FAILED; fi echo $MONITOR_FINISHED; } function web-stop-tested { # This version runs without testing for GSDLHOME # Useful to be run as a target when we know test-gsdlhome has already # been done. This avoids an unnecessary repetition of printing # out the values of GSDLHOME and GSDLOS if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl stop ; fi } function web-stop { test-gsdlhome web-stop-tested if [ $? = 0 ] ; then echo $MONITOR_SUCCESS; else echo $MONITOR_FAILED; fi echo $MONITOR_FINISHED; } function usage { echo "" echo " Usage: $0 " echo " where is any of the following: " echo " web-start" echo " web-stop" echo " web-restart" echo " web-status" echo " web-graceful" echo " configure-admin" echo " configure-web [config-filename]" echo " configure-apache [config-filename]" echo " configure-cgi" echo " reset-gsdlhome [config-filename]\n\t(Save a copy of $cgibin/gsdlsite.cfg to preserve any customisations)" echo " test-gsdlhome" echo " web-stop-tested" echo "" } if [[ $# < 1 || $# > 2 ]] ; then usage exit 0 fi target=$1 configfile=$2 # remove any extraneous double quotes configfile=${configfile//\"/} case $target in web-start) web-start;; web-stop) web-stop;; web-restart) web-restart;; web-status) web-status;; web-graceful) web-graceful;; configure-admin) configure-admin;; configure-web) configure-web $configfile;; configure-apache) configure-apache $configfile;; configure-cgi) configure-cgi;; set-port) configure-port-and-connection;; reset-gsdlhome) reset-gsdlhome;; test-gsdlhome) test-gsdlhome;; web-stop-tested) web-stop-tested;; *) echo echo "Command unrecognised: $target" usage;; esac exit;