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