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