source: main/tags/stable/greenstone2/gsicontrol.bat@ 23214

Last change on this file since 23214 was 22613, checked in by ak19, 14 years ago

Still ticket 152: allowing other collectdirs. For the apache web server to display images in a collection, the httpd.conf file must be set up for it

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