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