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