source: main/tags/3.04/gsdl/gsicontrol.bat@ 21191

Last change on this file since 21191 was 20262, checked in by ak19, 15 years ago

The minor changes to make this script behave like the bash equivalent, before testing and committing the changes for configure-apache.

File size: 6.6 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
54 echo.
55 echo Environment variable GSDLHOME (or GSDLOS) not set.
56 echo This needs to be set to run the gsicontrol command %target%.
57 echo Have you run setup.bat?
58 echo.
59 goto 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
73rem if "%target%" == "web-status" goto status
74rem if "%target%" == "web-graceful" goto graceful
75if "%target%" == "configure-admin" goto cfgadmin
76if "%target%" == "configure-web" goto cfgweb
77if "%target%" == "configure-apache" goto cfgapach
78if "%target%" == "configure-cgi" goto cfgcgi
79:: already tested gsdlhome (and web-stop-tested) above, don't want to keep looping on it
80if "%target%" == "test-gsdlhome" goto exit
81rem if "%target%" == "web-stop-tested" goto exit
82if "%target%" == "portcon" goto portcon1
83 :: unknown command
84 echo Command unrecognised: %target%
85 goto usage
86
87:start
88:: START starts the app in a new console named by the string following immediately thereafter
89:: then we start up apache-httpd and pass the signal that the stop command will respond to
90START "%GSDLHOME%\apachectl" "%GSDLHOME%\bin\windows\starthttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
91echo %MONITOR_SUCCESS%
92echo %MONITOR_FINISHED%
93goto exit
94
95:stop
96:stoptest
97if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL%
98if "%target%" == "web-stop-tested" goto exit
99echo %MONITOR_SUCCESS%
100echo %MONITOR_FINISHED%
101goto exit
102
103:restart
104if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL%
105:: wait 4s, see http://malektips.com/dos0017.html. The number in the 2nd line is variable (number of seconds to wait)
106ping 127.0.0.1 -n 2 -w 1000 > nul
107ping 127.0.0.1 -n 4 -w 1000> nul
108::"%GSDLHOME%\bin\windows\starthttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
109goto start
110
111:status
112:graceful
113::echo Command %target% is not yet operational (no local apache web server included in this release).
114goto exit
115
116::configure-web
117::configure-cgi
118:cfgweb
119:cfgcgi
120if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg
121 echo Configuring cgi-bin\gsdlsite.cfg
122 for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\\\\@g"') do set safepath=%%T
123 bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg
124 set safepath=
125 goto cgifin
126
127:cgimsg
128echo WARNING: Nothing done for make configure-cgi.
129echo If you wish to regenerate the file
130echo %GSDLHOME%\cgi-bin\gsdlsite.cfg
131echo from scratch, delete the existing file first.
132echo.
133
134:cgifin
135if "%target%" == "configure-cgi" goto exit
136if "%target%" == "configure-web" goto cfgapach
137
138::configure-apache
139:cfgapach
140if exist "%GSDLHOME%\llssite.cfg" goto exit
141if not exist "%GSDLHOME%\llssite.cfg.in" goto exit
142 copy llssite.cfg.in llssite.cfg
143 set configfile="%GSDLHOME%\llssite.cfg"
144 goto exit
145
146::configure-admin
147:cfgadmin
148echo.
149echo Configuring admin user password:
150for /F %%T in ('getpw') do set encrypted_password=%%T
151
152:: Have to create an intermediate file in the following, because echoing
153:: lines straight into a pipe adds spaces before the end of each line.
154:: When piping, need to double-escape the angle brackets with three hat signs,
155:: but when redirecting to a file, need to escape only once (one hat sign).
156if ERRORLEVEL 0 (
157 (
158 echo [admin]
159 echo ^<enabled^>true
160 echo ^<groups^>administrator,colbuilder,all-collections-editor
161 echo ^<password^>%encrypted_password%
162 echo ^<username^>admin
163 ) > "%GSDLHOME%\etc\users.txt"
164 type "%GSDLHOME%\etc\users.txt" | txt2db -append "%GSDLHOME%\etc\users.gdb"
165 del "%GSDLHOME%\etc\users.txt"
166) else (
167 echo Did not set password
168)
169echo.
170goto exit
171
172::configure-port-and-connection
173:portcon1
174set /p port=Enter port number to use:
175set /p connect=Allow external connections [yes/no]:
176if "%connect%" == "yes" set allowfrom="all" goto portcon2
177if "%connect%" == "y" set allowfrom="all" goto portcon2
178set allowfrom="127.0.0.1"
179
180:portcon2
181if "%port%" == "" echo Done& goto exit
182 set _sed="bin\windows\sed.exe"
183 for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
184
185 echo Port: %port%
186 echo Stopping web server (if running)
187 if not exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo Missing conf file
188 if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
189 echo Setting config file to use port %port%
190 type "%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"
191 echo Type '%0 web-start' to start the web server running on port %port%
192 echo Done
193 set port=
194 set connect=
195 set allowfrom=
196 set _sed=
197 set safepath=
198
199
200:exit
201endlocal
Note: See TracBrowser for help on using the repository browser.