[18851] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
[19250] | 3 | testdone=0
|
---|
| 4 |
|
---|
[18851] | 5 | function test-gsdlhome {
|
---|
[19250] | 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
|
---|
[18851] | 20 | fi
|
---|
[19250] | 21 | }
|
---|
[18851] | 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" \
|
---|
[19140] | 43 | | txt2db -append "$GSDLHOME/etc/users.gdb" ;
|
---|
[18851] | 44 | else
|
---|
| 45 | echo "Did not set password" ;
|
---|
| 46 | fi
|
---|
| 47 | echo ""
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[19250] | 50 |
|
---|
| 51 | function _configure-port-and-connection {
|
---|
[18851] | 52 | test-gsdlhome
|
---|
| 53 | echo "Enter port number to use:"
|
---|
| 54 | read port ;
|
---|
[19250] | 55 | echo "Allow external connections [yes/no]:"
|
---|
| 56 | read connection ;
|
---|
| 57 | if [ $connection = "yes" ] || [ $connection = "y" ] ; then
|
---|
| 58 | allowfrom="all"
|
---|
| 59 | else
|
---|
| 60 | allowfrom="127.0.0.1"
|
---|
| 61 | fi
|
---|
| 62 |
|
---|
[18851] | 63 | if test ! -z $port ; then
|
---|
| 64 | echo "Port: $port" ;
|
---|
| 65 | echo "Stopping web server (if running)" ;
|
---|
| 66 | web-stop-tested ;
|
---|
| 67 | echo "Setting config file to use port $port";
|
---|
| 68 | cat "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf.in" \
|
---|
| 69 | | sed "s@\*\*PORT\*\*@$port@g" \
|
---|
[19257] | 70 | | sed "s@\*\*CONNECTION\*\*@$allowfrom@g" \
|
---|
[18851] | 71 | | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
|
---|
| 72 | | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS@g" \
|
---|
| 73 | > "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ;
|
---|
| 74 | echo "Type '$0 web-start' to start the web server running on port $port" ;
|
---|
| 75 | fi ;
|
---|
| 76 | echo "Done" ;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | MONITOR_SUCCESS="MAKE SUCCESSFUL"
|
---|
| 81 | MONITOR_FAILED="MAKE FAILED"
|
---|
| 82 | MONITOR_FINISHED="MAKE DONE"
|
---|
| 83 |
|
---|
| 84 | function configure-apache {
|
---|
| 85 | test-gsdlhome
|
---|
[18866] | 86 | configfile=$1 ;
|
---|
[19023] | 87 | # if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
|
---|
[18866] | 88 | if [ "x$configfile" = "x" ]; then
|
---|
[19023] | 89 | if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
|
---|
| 90 | cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
|
---|
| 91 | fi
|
---|
[18866] | 92 | configfile="$GSDLHOME/llssite.cfg";
|
---|
| 93 | fi ;
|
---|
[18851] | 94 | echo "Configuring the apache webserver..." ;
|
---|
[18866] | 95 | port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
|
---|
[19250] | 96 |
|
---|
| 97 | externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
|
---|
| 98 | if [ $externalaccess == "1" ] ; then
|
---|
| 99 | externalaccess="yes"
|
---|
| 100 | else
|
---|
| 101 | externalaccess="no"
|
---|
| 102 | fi
|
---|
| 103 |
|
---|
| 104 | echo -e "$port\n$externalaccess" | _configure-port-and-connection ;
|
---|
[18851] | 105 | if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
|
---|
| 106 | echo $MONITOR_SUCCESS;
|
---|
| 107 | else
|
---|
| 108 | echo $MONITOR_FAILED;
|
---|
| 109 | fi
|
---|
| 110 | echo $MONITOR_FINISHED
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | function configure-web {
|
---|
| 114 | configure-cgi
|
---|
[18866] | 115 | configure-apache $1
|
---|
[18851] | 116 | }
|
---|
| 117 |
|
---|
| 118 | function web-status {
|
---|
| 119 | test-gsdlhome
|
---|
| 120 | $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl status
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | function web-start {
|
---|
| 124 | test-gsdlhome
|
---|
| 125 | $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl start
|
---|
| 126 | echo $MONITOR_SUCCESS
|
---|
| 127 | echo $MONITOR_FINISHED
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | function web-restart {
|
---|
| 131 | test-gsdlhome
|
---|
| 132 | $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart
|
---|
| 133 | echo $MONITOR_SUCCESS
|
---|
| 134 | echo $MONITOR_FINISHED
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | function web-graceful {
|
---|
| 138 | test-gsdlhome
|
---|
| 139 | $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful
|
---|
| 140 | echo $MONITOR_SUCCESS
|
---|
| 141 | echo $MONITOR_FINISHED
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | function web-stop-tested {
|
---|
| 145 | # This version runs without testing for GSDLHOME
|
---|
| 146 | # Useful to be run as a target when we know test-gsdlhome has already
|
---|
| 147 | # been done. This avoids a unnecessary repetition of printing
|
---|
| 148 | # out the values of GSDLHOME and GSDLOS
|
---|
| 149 | if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
|
---|
| 150 | $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl stop ;
|
---|
| 151 | fi
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | function web-stop {
|
---|
| 155 | test-gsdlhome
|
---|
| 156 | web-stop-tested
|
---|
| 157 | echo $MONITOR_SUCCESS
|
---|
| 158 | echo $MONITOR_FINISHED
|
---|
| 159 | }
|
---|
| 160 |
|
---|
[19453] | 161 | function usage {
|
---|
[18851] | 162 | echo ""
|
---|
| 163 | echo " Usage: $0 <command>"
|
---|
| 164 | echo " where <command> is any of the following: "
|
---|
| 165 | echo " web-start"
|
---|
| 166 | echo " web-stop"
|
---|
| 167 | echo " web-restart"
|
---|
| 168 | echo " web-status"
|
---|
| 169 | echo " web-graceful"
|
---|
| 170 | echo " configure-admin"
|
---|
[18866] | 171 | echo " configure-web [config-filename]"
|
---|
| 172 | echo " configure-apache [config-filename]"
|
---|
[18851] | 173 | echo " configure-cgi"
|
---|
| 174 | echo " test-gsdlhome"
|
---|
| 175 | echo " web-stop-tested"
|
---|
| 176 | echo ""
|
---|
[19453] | 177 | }
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | if [[ $# < 1 || $# > 2 ]] ; then
|
---|
| 181 | usage
|
---|
[18851] | 182 | exit 0
|
---|
| 183 | fi
|
---|
| 184 |
|
---|
| 185 | target=$1
|
---|
[18866] | 186 | configfile=$2
|
---|
[18851] | 187 |
|
---|
| 188 | case $target in
|
---|
| 189 | web-start)
|
---|
| 190 | web-start;;
|
---|
| 191 | web-stop)
|
---|
| 192 | web-stop;;
|
---|
| 193 | web-restart)
|
---|
| 194 | web-restart;;
|
---|
| 195 | web-status)
|
---|
| 196 | web-status;;
|
---|
| 197 | web-graceful)
|
---|
| 198 | web-graceful;;
|
---|
| 199 | configure-admin)
|
---|
| 200 | configure-admin;;
|
---|
| 201 | configure-web)
|
---|
[18866] | 202 | configure-web $configfile;;
|
---|
[18851] | 203 | configure-apache)
|
---|
[18866] | 204 | configure-apache $configfile;;
|
---|
[18851] | 205 | configure-cgi)
|
---|
| 206 | configure-cgi;;
|
---|
| 207 | test-gsdlhome)
|
---|
| 208 | test-gsdlhome;;
|
---|
| 209 | web-stop-tested)
|
---|
| 210 | web-stop-tested;;
|
---|
[19453] | 211 | *)
|
---|
| 212 | echo
|
---|
| 213 | echo "Command unrecognised: $target"
|
---|
| 214 | usage;;
|
---|
| 215 |
|
---|
[18851] | 216 | esac
|
---|
| 217 |
|
---|
[19257] | 218 | exit;
|
---|