1 | @echo off
|
---|
2 |
|
---|
3 | setlocal
|
---|
4 | ::set testdone=0
|
---|
5 | set target=%1
|
---|
6 | set 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
|
---|
9 | if not [%2] == [] set configfile=%configfile:"=%
|
---|
10 |
|
---|
11 | :: Construct the signal using the unique GS2 installation
|
---|
12 | :: directory (after replacing spaces, colons and backslashes)
|
---|
13 | set signal=%GSDLHOME: =_%
|
---|
14 | for /F "delims=*" %%T in ('"echo %signal%| bin\windows\sed.exe s@[\\:]@_@g"') do set signal=%%T
|
---|
15 | set GS2_APACHE_HTTPD_SIGNAL=GS2_APACHE_HTTPD_%signal%
|
---|
16 | set signal=
|
---|
17 | rem echo Signal is: %GS2_APACHE_HTTPD_SIGNAL%
|
---|
18 |
|
---|
19 | :: Need to get greenstone installation directory
|
---|
20 | :: set cwd=%CD%
|
---|
21 |
|
---|
22 | set MONITOR_SUCCESS=MAKE SUCCESSFUL
|
---|
23 | set MONITOR_FAILED=MAKE FAILED
|
---|
24 | set MONITOR_FINISHED=MAKE DONE
|
---|
25 |
|
---|
26 | :: check that we have >=1 and <=2 arguments
|
---|
27 | :chkargs
|
---|
28 | if "%target%" == "" goto usage
|
---|
29 | if not "%3" == "" goto usage
|
---|
30 | goto begincmd
|
---|
31 |
|
---|
32 |
|
---|
33 | :usage
|
---|
34 | echo.
|
---|
35 | echo Usage: %0 command
|
---|
36 | echo where command is any of the following:
|
---|
37 | echo web-start
|
---|
38 | echo web-stop
|
---|
39 | echo web-restart
|
---|
40 | ::echo web-status
|
---|
41 | ::echo web-graceful
|
---|
42 | echo configure-admin
|
---|
43 | echo configure-web [config-filename]
|
---|
44 | echo configure-apache [config-filename]
|
---|
45 | echo configure-cgi
|
---|
46 | echo set-port
|
---|
47 | echo test-gsdlhome
|
---|
48 | echo web-stop-tested
|
---|
49 | echo.
|
---|
50 | goto exit
|
---|
51 |
|
---|
52 |
|
---|
53 | :begincmd
|
---|
54 | :: web-stop-tested command assumes GSDLHOME/greenstone environment is already set
|
---|
55 | if "%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
|
---|
59 | if NOT "%GSDLHOME%" == "" if NOT "%GSDLOS%" == "" goto commands
|
---|
60 | echo.
|
---|
61 | echo Environment variable GSDLHOME (or GSDLOS) not set.
|
---|
62 | echo This needs to be set to run the gsicontrol command %target%.
|
---|
63 | echo Have you run setup.bat?
|
---|
64 | echo.
|
---|
65 | goto exit
|
---|
66 |
|
---|
67 |
|
---|
68 | ::MAIN MENU
|
---|
69 | :commands
|
---|
70 | echo.
|
---|
71 | echo Using:
|
---|
72 | echo GSDLHOME = %GSDLHOME%
|
---|
73 | echo GSDLOS = %GSDLOS%
|
---|
74 | echo.
|
---|
75 |
|
---|
76 | if "%target%" == "web-start" goto start
|
---|
77 | if "%target%" == "web-stop" goto stop
|
---|
78 | if "%target%" == "web-restart" goto restart
|
---|
79 | if "%target%" == "configure-admin" goto cfgadmin
|
---|
80 | if "%target%" == "configure-web" goto cfgweb
|
---|
81 | if "%target%" == "configure-apache" goto cfgapach
|
---|
82 | if "%target%" == "configure-cgi" goto cfgcgi
|
---|
83 | :: already tested gsdlhome (and web-stop-tested) above, don't want to keep looping on it
|
---|
84 | if "%target%" == "test-gsdlhome" goto exit
|
---|
85 | rem if "%target%" == "web-stop-tested" goto exit
|
---|
86 | rem if "%target%" == "web-status" goto status
|
---|
87 | rem if "%target%" == "web-graceful" goto graceful
|
---|
88 | if "%target%" == "set-port" goto setport
|
---|
89 | :: unknown command
|
---|
90 | echo Command unrecognised: %target%
|
---|
91 | goto 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
|
---|
97 | START "%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:
|
---|
99 | if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
|
---|
100 | echo %MONITOR_FINISHED%
|
---|
101 | goto exit
|
---|
102 |
|
---|
103 | :stop
|
---|
104 | :stoptest
|
---|
105 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
|
---|
106 | if "%target%" == "web-stop-tested" goto exit
|
---|
107 | :: if the return value is >= 0, it's succeeded:
|
---|
108 | if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
|
---|
109 | echo %MONITOR_FINISHED%
|
---|
110 | goto 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
|
---|
116 | if 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
|
---|
120 | ping -n 1 -w 1000 127.0.0.1 |find "TTL=">nul || goto failmsg
|
---|
121 | echo Waiting for re-start....
|
---|
122 | ping -n 5 -w 1000 127.0.0.1> nul
|
---|
123 | goto start
|
---|
124 |
|
---|
125 | :failmsg
|
---|
126 | echo Unable to wait for restart. Manually run %0 web-start
|
---|
127 | goto 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
|
---|
138 | echo.
|
---|
139 | echo Configuring admin user password:
|
---|
140 | for /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).
|
---|
146 | if 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 | )
|
---|
159 | echo.
|
---|
160 | goto exit
|
---|
161 |
|
---|
162 |
|
---|
163 | ::configure-web
|
---|
164 | ::configure-cgi
|
---|
165 | :cfgweb
|
---|
166 | :cfgcgi
|
---|
167 | if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg
|
---|
168 | echo Configuring cgi-bin\gsdlsite.cfg
|
---|
169 | for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\\\\@g"') do set safepath=%%T
|
---|
170 | bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg
|
---|
171 | set safepath=
|
---|
172 | goto cgifin
|
---|
173 |
|
---|
174 | :cgimsg
|
---|
175 | echo WARNING: Nothing done for configure-cgi.
|
---|
176 | echo If you wish to regenerate the file
|
---|
177 | echo %GSDLHOME%\cgi-bin\gsdlsite.cfg
|
---|
178 | echo from scratch, delete the existing file first.
|
---|
179 | echo.
|
---|
180 |
|
---|
181 | :cgifin
|
---|
182 | if "%target%" == "configure-cgi" goto exit
|
---|
183 | if "%target%" == "configure-web" goto cfgapach
|
---|
184 |
|
---|
185 | ::configure-apache
|
---|
186 | :cfgapach
|
---|
187 | if not "%configfile%" == "" if exist "%configfile%" (goto cfgport) else (echo Config file %configfile% does not exist. Using default llssite.cfg)
|
---|
188 |
|
---|
189 | if exist "%GSDLHOME%\llssite.cfg" (
|
---|
190 | set configfile=%GSDLHOME%\llssite.cfg
|
---|
191 | goto cfgport
|
---|
192 | )
|
---|
193 | if 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 | )
|
---|
197 | copy "%GSDLHOME%\llssite.cfg.in" "%GSDLHOME%\llssite.cfg"
|
---|
198 | set configfile=%GSDLHOME%\llssite.cfg
|
---|
199 |
|
---|
200 | :cfgport
|
---|
201 | echo 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)
|
---|
203 | FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^portnumber "%configfile%"') do set port=%%G
|
---|
204 | FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^hostIP "%configfile%"') do set hostIP=%%G
|
---|
205 | FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^externalaccess "%configfile%"') do set allowfromall=%%G
|
---|
206 |
|
---|
207 | if "%allowfromall%" == "1" set allowfromall="Allow"& goto portcon
|
---|
208 | set 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
|
---|
213 | goto portcon
|
---|
214 |
|
---|
215 |
|
---|
216 | ::configure-port-and-connection
|
---|
217 | :setport
|
---|
218 | set /p port=Enter port number to use:
|
---|
219 | set /p hostIP=Enter host IP to allow (127.0.0.1 is included by default):
|
---|
220 | set /p allowfromall=Allow external connections [yes/no]:
|
---|
221 |
|
---|
222 | if "%allowfromall%" == "yes" set allowfromall="Allow"& goto portcon
|
---|
223 | if "%allowfromall%" == "y" set allowfromall="Allow"& goto portcon
|
---|
224 | set allowfromall="Deny"
|
---|
225 | goto portcon
|
---|
226 |
|
---|
227 | :portcon
|
---|
228 | if "%port%" == "" (
|
---|
229 | echo Done
|
---|
230 | goto exit
|
---|
231 | )
|
---|
232 | set _sed="bin\windows\sed.exe"
|
---|
233 | for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
|
---|
234 |
|
---|
235 | echo Port: %port%
|
---|
236 | echo Stopping web server (if running)
|
---|
237 | if not exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo Missing conf file
|
---|
238 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
|
---|
239 | echo Setting config file to use port %port%
|
---|
240 | type "%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@\*\*GSDLHOME\*\*@%safepath%@g" | %_sed% "s@\*\*APACHE_HOME_OS\*\*@%safepath%\/apache-httpd\/%GSDLOS%@g" > "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf"
|
---|
241 | echo Type '%0 web-start' to start the web server running on port %port%
|
---|
242 | echo Done
|
---|
243 |
|
---|
244 | set allowfromall=
|
---|
245 | set _sed=
|
---|
246 | set safepath=
|
---|
247 | set port=
|
---|
248 |
|
---|
249 | :: Extra processing for configure-web and configure-cgi command targets
|
---|
250 | if not "%target%" == "configure-web" if not "%target%" == "configure-cgi" goto exit
|
---|
251 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
|
---|
252 | echo %MONITOR_FINISHED%
|
---|
253 | goto exit
|
---|
254 |
|
---|
255 | :exit
|
---|
256 | endlocal
|
---|