[19278] | 1 | @echo off
|
---|
| 2 |
|
---|
[19970] | 3 | setlocal
|
---|
[20262] | 4 | ::set testdone=0
|
---|
[19278] | 5 | set target=%1
|
---|
| 6 | set configfile=%2
|
---|
[20906] | 7 | :: remove any quotes around configfile, if we were given parameter configfile
|
---|
| 8 | :: To test for the existence of a cmdline parameter: http://ss64.com/nt/if.html
|
---|
| 9 | if not [%2] == [] set configfile=%configfile:"=%
|
---|
[19278] | 10 |
|
---|
[20262] | 11 | :: Construct the signal using the unique GS2 installation
|
---|
[20906] | 12 | :: directory (after replacing spaces, colons and backslashes)
|
---|
| 13 | set signal=%GSDLHOME: =_%
|
---|
| 14 | for /F "delims=*" %%T in ('"echo %signal%| bin\windows\sed.exe s@[\\:]@_@g"') do set signal=%%T
|
---|
[20262] | 15 | set GS2_APACHE_HTTPD_SIGNAL=GS2_APACHE_HTTPD_%signal%
|
---|
[20906] | 16 | set signal=
|
---|
[20262] | 17 | rem echo Signal is: %GS2_APACHE_HTTPD_SIGNAL%
|
---|
| 18 |
|
---|
[19970] | 19 | :: Need to get greenstone installation directory
|
---|
| 20 | :: set cwd=%CD%
|
---|
[19278] | 21 |
|
---|
[19970] | 22 | set MONITOR_SUCCESS=MAKE SUCCESSFUL
|
---|
| 23 | set MONITOR_FAILED=MAKE FAILED
|
---|
| 24 | set MONITOR_FINISHED=MAKE DONE
|
---|
| 25 |
|
---|
[19278] | 26 | :: check that we have >=1 and <=2 arguments
|
---|
| 27 | :chkargs
|
---|
[20262] | 28 | if "%target%" == "" goto usage
|
---|
| 29 | if not "%3" == "" goto usage
|
---|
[19278] | 30 | goto begincmd
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | :usage
|
---|
| 34 | echo.
|
---|
| 35 | echo Usage: %0 command
|
---|
| 36 | echo where command is any of the following:
|
---|
[19970] | 37 | echo web-start
|
---|
| 38 | echo web-stop
|
---|
| 39 | echo web-restart
|
---|
[20262] | 40 | ::echo web-status
|
---|
| 41 | ::echo web-graceful
|
---|
[19278] | 42 | echo configure-admin
|
---|
| 43 | echo configure-web [config-filename]
|
---|
| 44 | echo configure-apache [config-filename]
|
---|
| 45 | echo configure-cgi
|
---|
[20637] | 46 | echo set-port
|
---|
[20262] | 47 | echo test-gsdlhome
|
---|
| 48 | echo web-stop-tested
|
---|
[19278] | 49 | echo.
|
---|
| 50 | goto exit
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | :begincmd
|
---|
| 54 | :: web-stop-tested command assumes GSDLHOME/greenstone environment is already set
|
---|
| 55 | if "%target%" == "web-stop-tested" goto stoptest
|
---|
| 56 |
|
---|
| 57 | :: For all other commands, the greenstone environment needs to be set first before they can be run
|
---|
| 58 | :testgsdl
|
---|
[20159] | 59 | if NOT "%GSDLHOME%" == "" if NOT "%GSDLOS%" == "" goto commands
|
---|
[20338] | 60 | echo.
|
---|
| 61 | echo Environment variable GSDLHOME (or GSDLOS) not set.
|
---|
| 62 | echo This needs to be set to run the gsicontrol command %target%.
|
---|
| 63 | echo Have you run setup.bat?
|
---|
| 64 | echo.
|
---|
| 65 | goto exit
|
---|
[19278] | 66 |
|
---|
| 67 |
|
---|
| 68 | ::MAIN MENU
|
---|
| 69 | :commands
|
---|
[20262] | 70 | echo.
|
---|
| 71 | echo Using:
|
---|
| 72 | echo GSDLHOME = %GSDLHOME%
|
---|
| 73 | echo GSDLOS = %GSDLOS%
|
---|
| 74 | echo.
|
---|
| 75 |
|
---|
[19278] | 76 | if "%target%" == "web-start" goto start
|
---|
| 77 | if "%target%" == "web-stop" goto stop
|
---|
| 78 | if "%target%" == "web-restart" goto restart
|
---|
| 79 | if "%target%" == "configure-admin" goto cfgadmin
|
---|
| 80 | if "%target%" == "configure-web" goto cfgweb
|
---|
| 81 | if "%target%" == "configure-apache" goto cfgapach
|
---|
| 82 | if "%target%" == "configure-cgi" goto cfgcgi
|
---|
[20262] | 83 | :: already tested gsdlhome (and web-stop-tested) above, don't want to keep looping on it
|
---|
| 84 | if "%target%" == "test-gsdlhome" goto exit
|
---|
| 85 | rem if "%target%" == "web-stop-tested" goto exit
|
---|
[20338] | 86 | rem if "%target%" == "web-status" goto status
|
---|
| 87 | rem if "%target%" == "web-graceful" goto graceful
|
---|
| 88 | if "%target%" == "set-port" goto setport
|
---|
| 89 | :: unknown command
|
---|
| 90 | echo Command unrecognised: %target%
|
---|
| 91 | goto usage
|
---|
[19278] | 92 |
|
---|
[20338] | 93 |
|
---|
[19278] | 94 | :start
|
---|
[20159] | 95 | :: START starts the app in a new console named by the string following immediately thereafter
|
---|
| 96 | :: then we start up apache-httpd and pass the signal that the stop command will respond to
|
---|
[20262] | 97 | START "%GSDLHOME%\apachectl" "%GSDLHOME%\bin\windows\starthttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
|
---|
[20639] | 98 | :: if the return value is >= 0, it's succeeded:
|
---|
| 99 | if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
|
---|
[19970] | 100 | echo %MONITOR_FINISHED%
|
---|
| 101 | goto exit
|
---|
| 102 |
|
---|
[19278] | 103 | :stop
|
---|
[20262] | 104 | :stoptest
|
---|
[20435] | 105 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
|
---|
[20262] | 106 | if "%target%" == "web-stop-tested" goto exit
|
---|
[20639] | 107 | :: if the return value is >= 0, it's succeeded:
|
---|
| 108 | if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
|
---|
[20262] | 109 | echo %MONITOR_FINISHED%
|
---|
[19970] | 110 | goto exit
|
---|
| 111 |
|
---|
[20637] | 112 |
|
---|
[19278] | 113 | :restart
|
---|
[20637] | 114 | :: Need to stop server, wait and start it again.
|
---|
| 115 | :: We're using Ping to implement batch file Wait
|
---|
[20262] | 116 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL%
|
---|
[20637] | 117 |
|
---|
| 118 | :: Wait 5 seconds and then start. See http://ss64.com/nt/sleep.html (and http://malektips.com/dos0017.html)
|
---|
| 119 | :: if loopback IP address (127.0.0.1) does not exist, we ask them to manually start it up again
|
---|
| 120 | ping -n 1 -w 1000 127.0.0.1 |find "TTL=">nul || goto failmsg
|
---|
| 121 | echo Waiting for re-start....
|
---|
| 122 | ping -n 5 -w 1000 127.0.0.1> nul
|
---|
[19970] | 123 | goto start
|
---|
| 124 |
|
---|
[20637] | 125 | :failmsg
|
---|
| 126 | echo Unable to wait for restart. Manually run %0 web-start
|
---|
| 127 | goto exit
|
---|
| 128 |
|
---|
| 129 |
|
---|
[20338] | 130 | ::status
|
---|
| 131 | ::graceful
|
---|
| 132 | ::echo Command %target% is not operational on this operating system
|
---|
| 133 | ::goto exit
|
---|
[19278] | 134 |
|
---|
| 135 |
|
---|
| 136 | ::configure-admin
|
---|
| 137 | :cfgadmin
|
---|
| 138 | echo.
|
---|
[19288] | 139 | echo Configuring admin user password:
|
---|
| 140 | for /F %%T in ('getpw') do set encrypted_password=%%T
|
---|
[19290] | 141 |
|
---|
| 142 | :: Have to create an intermediate file in the following, because echoing
|
---|
| 143 | :: lines straight into a pipe adds spaces before the end of each line.
|
---|
[19970] | 144 | :: When piping, need to double-escape the angle brackets with three hat signs,
|
---|
[19290] | 145 | :: but when redirecting to a file, need to escape only once (one hat sign).
|
---|
[19288] | 146 | if ERRORLEVEL 0 (
|
---|
| 147 | (
|
---|
| 148 | echo [admin]
|
---|
[19290] | 149 | echo ^<enabled^>true
|
---|
| 150 | echo ^<groups^>administrator,colbuilder,all-collections-editor
|
---|
| 151 | echo ^<password^>%encrypted_password%
|
---|
| 152 | echo ^<username^>admin
|
---|
| 153 | ) > "%GSDLHOME%\etc\users.txt"
|
---|
| 154 | type "%GSDLHOME%\etc\users.txt" | txt2db -append "%GSDLHOME%\etc\users.gdb"
|
---|
| 155 | del "%GSDLHOME%\etc\users.txt"
|
---|
[19288] | 156 | ) else (
|
---|
| 157 | echo Did not set password
|
---|
| 158 | )
|
---|
[20262] | 159 | echo.
|
---|
[19288] | 160 | goto exit
|
---|
[19278] | 161 |
|
---|
[20338] | 162 |
|
---|
| 163 | ::configure-web
|
---|
| 164 | ::configure-cgi
|
---|
| 165 | :cfgweb
|
---|
| 166 | :cfgcgi
|
---|
| 167 | if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg
|
---|
| 168 | echo Configuring cgi-bin\gsdlsite.cfg
|
---|
| 169 | for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\\\\@g"') do set safepath=%%T
|
---|
| 170 | bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg
|
---|
| 171 | set safepath=
|
---|
| 172 | goto cgifin
|
---|
| 173 |
|
---|
| 174 | :cgimsg
|
---|
| 175 | echo WARNING: Nothing done for configure-cgi.
|
---|
| 176 | echo If you wish to regenerate the file
|
---|
| 177 | echo %GSDLHOME%\cgi-bin\gsdlsite.cfg
|
---|
| 178 | echo from scratch, delete the existing file first.
|
---|
| 179 | echo.
|
---|
| 180 |
|
---|
| 181 | :cgifin
|
---|
| 182 | if "%target%" == "configure-cgi" goto exit
|
---|
| 183 | if "%target%" == "configure-web" goto cfgapach
|
---|
| 184 |
|
---|
| 185 | ::configure-apache
|
---|
| 186 | :cfgapach
|
---|
| 187 | if not "%configfile%" == "" if exist "%configfile%" (goto cfgport) else (echo Config file %configfile% does not exist. Using default llssite.cfg)
|
---|
| 188 |
|
---|
| 189 | if exist "%GSDLHOME%\llssite.cfg" (
|
---|
[20906] | 190 | set configfile=%GSDLHOME%\llssite.cfg
|
---|
[20338] | 191 | goto cfgport
|
---|
| 192 | )
|
---|
| 193 | if not exist "%GSDLHOME%\llssite.cfg.in" (
|
---|
| 194 | echo Unable to proceed as neither %GSDLHOME%\llssite.cfg nor %GSDLHOME%\llssite.cfg.in could be found
|
---|
| 195 | goto exit
|
---|
| 196 | )
|
---|
| 197 | copy "%GSDLHOME%\llssite.cfg.in" "%GSDLHOME%\llssite.cfg"
|
---|
[20906] | 198 | set configfile=%GSDLHOME%\llssite.cfg
|
---|
[20338] | 199 |
|
---|
| 200 | :cfgport
|
---|
| 201 | echo Configuring the apache webserver...
|
---|
| 202 | :: See http://ss64.com/nt/for_cmd.html, http://ss64.com/nt/findstr.html (and http://ss64.com/nt/find.html)
|
---|
[20906] | 203 | FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^portnumber "%configfile%"') do set port=%%G
|
---|
| 204 | FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^hostIP "%configfile%"') do set hostIP=%%G
|
---|
[23252] | 205 | FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^hosts "%configfile%"') do set hosts=%%G
|
---|
[20906] | 206 | FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^externalaccess "%configfile%"') do set allowfromall=%%G
|
---|
[20338] | 207 |
|
---|
[20637] | 208 | if "%allowfromall%" == "1" set allowfromall="Allow"& goto portcon
|
---|
| 209 | set allowfromall="Deny"
|
---|
[20615] | 210 |
|
---|
[20338] | 211 | :: Using CALL to jump to labels means we can return from them. BUT need to ensure
|
---|
| 212 | :: that command extensions are enabled to call labels. So just use GOTO instead.
|
---|
| 213 | ::http://ss64.com/nt/call.html
|
---|
| 214 | goto portcon
|
---|
| 215 |
|
---|
[20637] | 216 |
|
---|
[19970] | 217 | ::configure-port-and-connection
|
---|
[20338] | 218 | :setport
|
---|
[19970] | 219 | set /p port=Enter port number to use:
|
---|
[20637] | 220 | set /p hostIP=Enter host IP to allow (127.0.0.1 is included by default):
|
---|
[23252] | 221 | set /p hosts=Enter hostname or list of hosts to allow (localhost included by default):
|
---|
[20637] | 222 | set /p allowfromall=Allow external connections [yes/no]:
|
---|
[20338] | 223 |
|
---|
[20637] | 224 | if "%allowfromall%" == "yes" set allowfromall="Allow"& goto portcon
|
---|
| 225 | if "%allowfromall%" == "y" set allowfromall="Allow"& goto portcon
|
---|
| 226 | set allowfromall="Deny"
|
---|
[20615] | 227 | goto portcon
|
---|
| 228 |
|
---|
[20338] | 229 | :portcon
|
---|
| 230 | if "%port%" == "" (
|
---|
[20505] | 231 | echo Done
|
---|
| 232 | goto exit
|
---|
[20338] | 233 | )
|
---|
| 234 | set _sed="bin\windows\sed.exe"
|
---|
| 235 | for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
|
---|
[19970] | 236 |
|
---|
[22613] | 237 | if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" FOR /F "tokens=2" %%G IN ('findstr /R ^collecthome "%GSDLHOME%\cgi-bin\gsdlsite.cfg"') do set COLLECTHOME=%%G
|
---|
| 238 | if "%COLLECTHOME%" == "" set COLLECTHOME=%GSDLHOME%\collect
|
---|
| 239 | for /F "delims=*" %%T in ('"echo %COLLECTHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safecollectpath=%%T
|
---|
| 240 |
|
---|
| 241 |
|
---|
[20338] | 242 | echo Port: %port%
|
---|
| 243 | echo Stopping web server (if running)
|
---|
| 244 | if not exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo Missing conf file
|
---|
| 245 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
|
---|
| 246 | echo Setting config file to use port %port%
|
---|
[23252] | 247 | type "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf.in" | %_sed% "s@\*\*PORT\*\*@%port%@g" | %_sed% "s@\*\*CONNECTPERMISSION\*\*@%allowfromall%@g" | %_sed% "s@\*\*HOST_IP\*\*@%hostIP%@g" | %_sed% "s@\*\*HOSTS\*\*@%hosts%@g" | %_sed% "s@\*\*COLLECTHOME\*\*@%safecollectpath%@g" | %_sed% "s@\*\*GSDLHOME\*\*@%safepath%@g" | %_sed% "s@\*\*APACHE_HOME_OS\*\*@%safepath%\/apache-httpd\/%GSDLOS%@g" > "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf"
|
---|
[20338] | 248 | echo Type '%0 web-start' to start the web server running on port %port%
|
---|
| 249 | echo Done
|
---|
[19970] | 250 |
|
---|
[20637] | 251 | set allowfromall=
|
---|
[20338] | 252 | set _sed=
|
---|
| 253 | set safepath=
|
---|
[20637] | 254 | set port=
|
---|
[20338] | 255 |
|
---|
| 256 | :: Extra processing for configure-web and configure-cgi command targets
|
---|
[20637] | 257 | if not "%target%" == "configure-web" if not "%target%" == "configure-cgi" goto exit
|
---|
[20338] | 258 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
|
---|
| 259 | echo %MONITOR_FINISHED%
|
---|
| 260 | goto exit
|
---|
| 261 |
|
---|
[19278] | 262 | :exit
|
---|
[19970] | 263 | endlocal
|
---|