source: main/trunk/greenstone2/gsicontrol.bat@ 24878

Last change on this file since 24878 was 24874, checked in by ak19, 12 years ago

Third set of commits to do with the migration of cgi-bin into common-src, so that upon make install, common-src\cgi-bin will be installed in cgi-bin\GSDLOS(GSDLARCH). The first commit was of changes to files in cgi-bin itself. The second commit was moving cgi-bin. This one involves changes to all the files referring to cgi-bin where this needs to be changed to cgi-bin\OS_and_ARCH.

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