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