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