#!/bin/bash function test-gsdlhome { 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 } function configure-cgi { test-gsdlhome if test ! -e $GSDLHOME/cgi-bin/gsdlsite.cfg ; then echo "Configuring cgi-bin/gsdlsite.cfg" ; sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg ; else echo "WARNING: Nothing done for make configure-cgi." ; echo " If you wish to regenerate the file " ; echo " $GSDLHOME/cgi-bin/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.db" ; else echo "Did not set password" ; fi echo "" } function configure-port { test-gsdlhome echo "Enter port number to use:" read port ; 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/conf/httpd.conf.in" \ | sed "s@\*\*PORT\*\*@$port@g" \ | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \ | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS@g" \ > "$GSDLHOME/apache-httpd/$GSDLOS/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 [ "x$configfile" = "x" ]; then configfile="$GSDLHOME/llssite.cfg"; fi ; echo "Configuring the apache webserver..." ; port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ; echo $port | configure-port ; if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then echo $MONITOR_SUCCESS; else echo $MONITOR_FAILED; fi echo $MONITOR_FINISHED } function configure-web { configure-cgi configure-apache $1 } function web-status { test-gsdlhome $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl status } function web-start { test-gsdlhome $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl start echo $MONITOR_SUCCESS echo $MONITOR_FINISHED } function web-restart { test-gsdlhome $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart echo $MONITOR_SUCCESS echo $MONITOR_FINISHED } function web-graceful { test-gsdlhome $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful echo $MONITOR_SUCCESS 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 a unnecessary repetition of printing # out the values of GSDLHOME and GSDLOS if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl stop ; fi } function web-stop { test-gsdlhome web-stop-tested echo $MONITOR_SUCCESS echo $MONITOR_FINISHED } if [[ $# < 1 || $# > 2 ]] ; then 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-port" echo " configure-cgi" echo " test-gsdlhome" echo " web-stop-tested" echo "" exit 0 fi target=$1 configfile=$2 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-port) configure-port;; configure-apache) configure-apache $configfile;; configure-cgi) configure-cgi;; test-gsdlhome) test-gsdlhome;; web-stop-tested) web-stop-tested;; esac exit;