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

Last change on this file since 22925 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
RevLine 
[19278]1@echo off
2
[19970]3setlocal
[20262]4::set testdone=0
[19278]5set target=%1
6set configfile=%2
[20906]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:"=%
[19278]10
[20262]11:: Construct the signal using the unique GS2 installation
[20906]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
[20262]15set GS2_APACHE_HTTPD_SIGNAL=GS2_APACHE_HTTPD_%signal%
[20906]16set signal=
[20262]17rem echo Signal is: %GS2_APACHE_HTTPD_SIGNAL%
18
[19970]19:: Need to get greenstone installation directory
20:: set cwd=%CD%
[19278]21
[19970]22set MONITOR_SUCCESS=MAKE SUCCESSFUL
23set MONITOR_FAILED=MAKE FAILED
24set MONITOR_FINISHED=MAKE DONE
25
[19278]26:: check that we have >=1 and <=2 arguments
27:chkargs
[20262]28if "%target%" == "" goto usage
29if not "%3" == "" goto usage
[19278]30 goto begincmd
31
32
33:usage
34echo.
35echo Usage: %0 command
36echo where command is any of the following:
[19970]37echo web-start
38echo web-stop
39echo web-restart
[20262]40::echo web-status
41::echo web-graceful
[19278]42echo configure-admin
43echo configure-web [config-filename]
44echo configure-apache [config-filename]
45echo configure-cgi
[20637]46echo set-port
[20262]47echo test-gsdlhome
48echo web-stop-tested
[19278]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
[20159]59if NOT "%GSDLHOME%" == "" if NOT "%GSDLOS%" == "" goto commands
[20338]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
[19278]66
67
68::MAIN MENU
69:commands
[20262]70echo.
71echo Using:
72echo GSDLHOME = %GSDLHOME%
73echo GSDLOS = %GSDLOS%
74echo.
75
[19278]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
[20262]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
[20338]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
[19278]92
[20338]93
[19278]94:start
[20159]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
[20262]97START "%GSDLHOME%\apachectl" "%GSDLHOME%\bin\windows\starthttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
[20639]98:: if the return value is >= 0, it's succeeded:
99if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
[19970]100echo %MONITOR_FINISHED%
101goto exit
102
[19278]103:stop
[20262]104:stoptest
[20435]105if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
[20262]106if "%target%" == "web-stop-tested" goto exit
[20639]107:: if the return value is >= 0, it's succeeded:
108if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
[20262]109echo %MONITOR_FINISHED%
[19970]110goto exit
111
[20637]112
[19278]113:restart
[20637]114:: Need to stop server, wait and start it again.
115:: We're using Ping to implement batch file Wait
[20262]116if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL%
[20637]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
[19970]123goto start
124
[20637]125:failmsg
126echo Unable to wait for restart. Manually run %0 web-start
127goto exit
128
129
[20338]130::status
131::graceful
132::echo Command %target% is not operational on this operating system
133::goto exit
[19278]134
135
136::configure-admin
137:cfgadmin
138echo.
[19288]139echo Configuring admin user password:
140for /F %%T in ('getpw') do set encrypted_password=%%T
[19290]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.
[19970]144:: When piping, need to double-escape the angle brackets with three hat signs,
[19290]145:: but when redirecting to a file, need to escape only once (one hat sign).
[19288]146if ERRORLEVEL 0 (
147 (
148 echo [admin]
[19290]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"
[19288]156) else (
157 echo Did not set password
158)
[20262]159echo.
[19288]160goto exit
[19278]161
[20338]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" (
[20906]190 set configfile=%GSDLHOME%\llssite.cfg
[20338]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"
[20906]198set configfile=%GSDLHOME%\llssite.cfg
[20338]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)
[20906]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
[20338]206
[20637]207if "%allowfromall%" == "1" set allowfromall="Allow"& goto portcon
208set allowfromall="Deny"
[20615]209
[20338]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
[20637]215
[19970]216::configure-port-and-connection
[20338]217:setport
[19970]218set /p port=Enter port number to use:
[20637]219set /p hostIP=Enter host IP to allow (127.0.0.1 is included by default):
220set /p allowfromall=Allow external connections [yes/no]:
[20338]221
[20637]222if "%allowfromall%" == "yes" set allowfromall="Allow"& goto portcon
223if "%allowfromall%" == "y" set allowfromall="Allow"& goto portcon
224set allowfromall="Deny"
[20615]225goto portcon
226
[20338]227:portcon
228if "%port%" == "" (
[20505]229 echo Done
230 goto exit
[20338]231)
232set _sed="bin\windows\sed.exe"
233for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
[19970]234
[22613]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
[20338]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%
[22613]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"
[20338]246echo Type '%0 web-start' to start the web server running on port %port%
247echo Done
[19970]248
[20637]249set allowfromall=
[20338]250set _sed=
251set safepath=
[20637]252set port=
[20338]253
254:: Extra processing for configure-web and configure-cgi command targets
[20637]255if not "%target%" == "configure-web" if not "%target%" == "configure-cgi" goto exit
[20338]256if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
257echo %MONITOR_FINISHED%
258goto exit
259
[19278]260:exit
[19970]261endlocal
Note: See TracBrowser for help on using the repository browser.