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