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

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

GSDLHOME placeholder is set to path to gsdlhome in .app files for Mac. Still need to test on windows

File size: 10.5 KB
Line 
1@echo off
2
3setlocal
4::set testdone=0
5
6set cgibin=cgi-bin
7::set cgibin=cgi-bin\windows
8
9set target=%1
10set 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
13if not [%2] == [] set configfile=%configfile:"=%
14
15:: Construct the signal using the unique GS2 installation
16:: directory (after replacing spaces, colons and backslashes)
17set signal=%GSDLHOME: =_%
18for /F "delims=*" %%T in ('"echo %signal%| bin\windows\sed.exe s@[\\:]@_@g"') do set signal=%%T
19set GS2_APACHE_HTTPD_SIGNAL=GS2_APACHE_HTTPD_%signal%
20set signal=
21rem echo Signal is: %GS2_APACHE_HTTPD_SIGNAL%
22
23:: Need to get greenstone installation directory
24:: set cwd=%CD%
25
26set MONITOR_SUCCESS=MAKE SUCCESSFUL
27set MONITOR_FAILED=MAKE FAILED
28set MONITOR_FINISHED=MAKE DONE
29
30:: check that we have >=1 and <=2 arguments
31:chkargs
32if "%target%" == "" goto usage
33if not "%3" == "" goto usage
34 goto begincmd
35
36
37:usage
38echo.
39echo Usage: %0 command
40echo where command is any of the following:
41echo web-start
42echo web-stop
43echo web-restart
44::echo web-status
45::echo web-graceful
46echo configure-admin
47echo configure-web [config-filename]
48echo configure-apache [config-filename]
49echo configure-cgi
50echo reset-gsdlhome [config-filename]
51echo (Save a copy of %cgibin%\gsdlsite.cfg to preserve any customisations)
52echo set-port
53echo test-gsdlhome
54echo web-stop-tested
55echo.
56goto exit
57
58
59:begincmd
60:: web-stop-tested command assumes GSDLHOME/greenstone environment is already set
61if "%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
65if NOT "%GSDLHOME%" == "" if NOT "%GSDLOS%" == "" goto commands
66echo.
67echo Environment variable GSDLHOME (or GSDLOS) not set.
68echo This needs to be set to run the gsicontrol command %target%.
69echo Have you run setup.bat?
70echo.
71goto exit
72
73
74::MAIN MENU
75:commands
76echo.
77echo Using:
78echo GSDLHOME = %GSDLHOME%
79echo GSDLOS = %GSDLOS%
80echo.
81
82if "%target%" == "web-start" goto start
83if "%target%" == "web-stop" goto stop
84if "%target%" == "web-restart" goto restart
85if "%target%" == "configure-admin" goto cfgadmin
86if "%target%" == "configure-web" goto cfgweb
87if "%target%" == "configure-apache" goto cfgapach
88if "%target%" == "configure-cgi" goto cfgcgi
89if "%target%" == "reset-gsdlhome" goto resethome
90:: already tested gsdlhome (and web-stop-tested) above, don't want to keep looping on it
91if "%target%" == "test-gsdlhome" goto exit
92rem if "%target%" == "web-stop-tested" goto exit
93rem if "%target%" == "web-status" goto status
94rem if "%target%" == "web-graceful" goto graceful
95if "%target%" == "set-port" goto setport
96:: unknown command
97echo Command unrecognised: %target%
98goto 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
104START "%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:
106if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
107echo %MONITOR_FINISHED%
108goto exit
109
110:stop
111:stoptest
112if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
113if "%target%" == "web-stop-tested" goto exit
114:: if the return value is >= 0, it's succeeded:
115if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
116echo %MONITOR_FINISHED%
117goto 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
123if 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
127ping -n 1 -w 1000 127.0.0.1 |find "TTL=">nul || goto failmsg
128echo Waiting for re-start....
129ping -n 5 -w 1000 127.0.0.1> nul
130goto start
131
132:failmsg
133echo Unable to wait for restart. Manually run %0 web-start
134goto 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
145echo.
146echo Configuring admin user password:
147for /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).
153if 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)
166echo.
167goto exit
168
169
170:: reset-gsdlhome forces configure-cgi by deleting gsdlsite.cfg
171:resethome
172echo.
173if 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
178set _sed="bin\windows\sed.exe"
179for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
180
181type "gs2-server.app/Contents/document.wflow.in" | %_sed% "s@\*\*GSDLHOME\*\*@%safepath%@g" > "gs2-server.app/Contents/document.wflow"
182type "gli.app/Contents/document.wflow.in" | %_sed% "s@\*\*GSDLHOME\*\*@%safepath%@g" > "gli.app/Contents/document.wflow"
183type "client-gli.app/Contents/document.wflow.in" | %_sed% "s@\*\*GSDLHOME\*\*@%safepath%@g" > "client-gli.app/Contents/document.wflow"
184type "gems.app/Contents/document.wflow.in" | %_sed% "s@\*\*GSDLHOME\*\*@%safepath%@g" > "gems.app/Contents/document.wflow"
185
186goto cfgweb
187
188
189::configure-web
190::configure-cgi
191:cfgweb
192:cfgcgi
193if exist "%GSDLHOME%\%cgibin%\gsdlsite.cfg" goto cgimsg
194echo Configuring %cgibin%\gsdlsite.cfg
195for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\\\\@g"') do set safepath=%%T
196bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" %cgibin%\gsdlsite.cfg.in > %cgibin%\gsdlsite.cfg
197set safepath=
198goto cgifin
199
200:cgimsg
201echo WARNING: Nothing done for configure-cgi.
202echo If you wish to regenerate the file
203echo %GSDLHOME%\%cgibin%\gsdlsite.cfg
204echo from scratch, delete the existing file first.
205echo.
206
207:cgifin
208if "%target%" == "configure-cgi" goto exit
209if "%target%" == "configure-web" goto cfgapach
210
211::configure-apache
212:cfgapach
213if not "%configfile%" == "" if exist "%configfile%" (goto cfgport) else (echo Config file %configfile% does not exist. Using default llssite.cfg)
214
215if exist "%GSDLHOME%\llssite.cfg" (
216 set configfile=%GSDLHOME%\llssite.cfg
217 goto cfgport
218)
219if not exist "%GSDLHOME%\llssite.cfg.in" (
220 echo Unable to proceed as neither %GSDLHOME%\llssite.cfg nor %GSDLHOME%\llssite.cfg.in could be found
221 goto exit
222)
223copy "%GSDLHOME%\llssite.cfg.in" "%GSDLHOME%\llssite.cfg"
224set configfile=%GSDLHOME%\llssite.cfg
225
226:cfgport
227echo Configuring the apache webserver...
228:: See http://ss64.com/nt/for_cmd.html, http://ss64.com/nt/findstr.html (and http://ss64.com/nt/find.html)
229FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^portnumber "%configfile%"') do set port=%%G
230FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^hostIP "%configfile%"') do set hostIP=%%G
231FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^hosts "%configfile%"') do set hosts=%%G
232FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^externalaccess "%configfile%"') do set allowfromall=%%G
233
234if "%allowfromall%" == "1" set allowfromall="Allow"& goto portcon
235set allowfromall="Deny"
236
237:: Using CALL to jump to labels means we can return from them. BUT need to ensure
238:: that command extensions are enabled to call labels. So just use GOTO instead.
239::http://ss64.com/nt/call.html
240goto portcon
241
242
243::configure-port-and-connection
244:setport
245set /p port=Enter port number to use:
246set /p hostIP=Enter host IP to allow (127.0.0.1 is included by default):
247set /p hosts=Enter hostname or list of hosts to allow (localhost included by default):
248set /p allowfromall=Allow external connections [yes/no]:
249
250if "%allowfromall%" == "yes" set allowfromall="Allow"& goto portcon
251if "%allowfromall%" == "y" set allowfromall="Allow"& goto portcon
252set allowfromall="Deny"
253goto portcon
254
255:portcon
256if "%port%" == "" (
257 echo Done
258 goto exit
259)
260if "%_sed%" == "" set _sed="bin\windows\sed.exe"
261if "%safepath%" == "" for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
262
263if exist "%GSDLHOME%\%cgibin%\gsdlsite.cfg" FOR /F "tokens=2" %%G IN ('findstr /R ^collecthome "%GSDLHOME%\%cgibin%\gsdlsite.cfg"') do set COLLECTHOME=%%G
264if "%COLLECTHOME%" == "" set COLLECTHOME=%GSDLHOME%\collect
265for /F "delims=*" %%T in ('"echo %COLLECTHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safecollectpath=%%T
266
267
268echo Port: %port%
269echo Stopping web server (if running)
270if not exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo Missing conf file
271if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
272echo Setting config file to use port %port%
273type "%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"
274echo Type '%0 web-start' to start the web server running on port %port%
275echo Done
276
277set allowfromall=
278set _sed=
279set safepath=
280set port=
281
282:: Extra processing for configure-web and configure-cgi command targets
283if not "%target%" == "configure-web" if not "%target%" == "configure-cgi" goto exit
284if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
285echo %MONITOR_FINISHED%
286goto exit
287
288:exit
289endlocal
Note: See TracBrowser for help on using the repository browser.