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

Last change on this file since 23945 was 23945, checked in by ak19, 13 years ago

First set of changes to the gsicontrol scripts to introduce the reset-gsdlhome flag. Still need to deal with the GSDLHOME placeholders in the Mac .app files and need to create their template .in files

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