source: gsdl/trunk/gsicontrol.bat@ 20562

Last change on this file since 20562 was 20505, checked in by ak19, 15 years ago

Corrected error in batch script: in label portcon, it tried to do two actions in one step without using the ampersand sign, so it didn't work properly before.

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