source: gsdl/trunk/gsicontrol.bat@ 19970

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

Added some further commands. portcon now allows one to specify the port and connection. This still needs to be called by the apache configure target. The functionality of gsicontrol isn't complete yet.

File size: 6.2 KB
Line 
1@echo off
2
3setlocal
4set testdone=0
5set target=%1
6set configfile=%2
7
8:: Need to get greenstone installation directory
9:: set cwd=%CD%
10
11set MONITOR_SUCCESS=MAKE SUCCESSFUL
12set MONITOR_FAILED=MAKE FAILED
13set MONITOR_FINISHED=MAKE DONE
14
15:: check that we have >=1 and <=2 arguments
16:chkargs
17if "%target%" == "" goto :usage
18if not "%3" == "" goto :usage
19 goto begincmd
20
21
22:usage
23echo.
24echo Usage: %0 command
25echo where command is any of the following:
26echo web-start
27echo web-stop
28echo web-restart
29echo configure-admin
30echo configure-web [config-filename]
31echo configure-apache [config-filename]
32echo configure-cgi
33
34::echo web-status
35::echo web-graceful
36::echo test-gsdlhome
37::echo web-stop-tested
38echo.
39goto exit
40
41
42:begincmd
43:: web-stop-tested command assumes GSDLHOME/greenstone environment is already set
44if "%target%" == "web-stop-tested" goto stoptest
45
46:: For all other commands, the greenstone environment needs to be set first before they can be run
47:testgsdl
48if NOT "%GSDLHOME%" == "" goto commands
49 echo.
50 echo Environment variable GSDLHOME not set.
51 echo This needs to be set to run the gsicontrol command %target%.
52 echo Have you run setup.bat?
53 echo.
54 goto exit
55
56
57::MAIN MENU
58:commands
59if "%target%" == "web-start" goto start
60if "%target%" == "web-stop" goto stop
61if "%target%" == "web-restart" goto restart
62if "%target%" == "web-status" goto status
63if "%target%" == "web-graceful" goto graceful
64if "%target%" == "configure-admin" goto cfgadmin
65if "%target%" == "configure-web" goto cfgweb
66if "%target%" == "configure-apache" goto cfgapach
67if "%target%" == "configure-cgi" goto cfgcgi
68if "%target%" == "test-gsdlhome" goto testgsdl
69if "%target%" == "portcon" goto portcon1
70 :: unknown command
71 goto usage
72
73:start
74"%GSDLHOME%\bin\windows\starthttpd.exe" GS2_APACHE_HTTPD "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
75echo %MONITOR_SUCCESS%
76echo %MONITOR_FINISHED%
77goto exit
78
79:stop
80if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD
81rem if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\apache-httpd\%GSDLOS%\bin\apachectl" stop
82echo %MONITOR_SUCCESS%
83echo %MONITOR_FINISHED%
84goto exit
85
86:restart
87if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD
88:: wait 2s, see http://malektips.com/dos0017.html. The 2 in the 2nd line is variable
89ping 127.0.0.1 -n 2 -w 1000 > nul
90ping 127.0.0.1 -n 2 -w 1000> nul
91::"%GSDLHOME%\bin\windows\starthttpd.exe" GS2_APACHE_HTTPD "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
92goto start
93
94:status
95:graceful
96::echo Command %target% is not yet operational (no local apache web server included in this release).
97goto exit
98
99:stoptest
100if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD
101rem if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\apache-httpd\%GSDLOS%\bin\apachectl" stop
102goto exit
103
104::configure-web
105::configure-cgi
106:cfgweb
107:cfgcgi
108if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg
109 echo Configuring cgi-bin\gsdlsite.cfg
110 set gsdlpath=%GSDLHOME%
111 for /F "delims=*" %%T in ('"echo %gsdlpath%| bin\windows\sed.exe s@\\@\\\\@g"') do set safepath=%%T
112 bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg
113 set gsdlpath=
114 set safepath=
115 goto cgifin
116
117:cgimsg
118echo WARNING: Nothing done for make configure-cgi.
119echo If you wish to regenerate the file
120echo %GSDLHOME%\cgi-bin\gsdlsite.cfg
121echo from scratch, delete the existing file first.
122echo.
123
124:cgifin
125if "%target%" == "configure-cgi" goto exit
126if "%target%" == "configure-web" goto cfgapach
127
128::configure-apache
129:cfgapach
130if exist "%GSDLHOME%\llssite.cfg" goto :exit
131if not exist "%GSDLHOME%\llssite.cfg.in" goto :exit
132 copy llssite.cfg.in llssite.cfg
133 set configfile="%GSDLHOME%\llssite.cfg"
134 goto exit
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)
159goto exit
160
161::configure-port-and-connection
162:portcon1
163set /p port=Enter port number to use:
164set /p connect=Allow external connections [yes/no]:
165if "%connect%" == "yes" set allowfrom="all" goto portcon2
166if "%connect%" == "y" set allowfrom="all" goto portcon2
167set allowfrom="127.0.0.1"
168
169:portcon2
170if "%port%" == "" goto exit
171 set _sed="bin\windows\sed.exe"
172 set gsdlpath=%GSDLHOME%
173 for /F "delims=*" %%T in ('"echo %gsdlpath%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
174
175 echo Port: %port%
176 echo Stopping web server (if running)
177 if not exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo missing conf file
178 if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD
179 echo Setting config file to use port %port%
180bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg
181 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"
182 echo Type '%0 web-start' to start the web server running on port %port%
183 echo Done
184 set port=
185 set connect=
186 set allowfrom=
187 set _sed=
188 set safepath=
189 set gsdlpath=
190
191
192:exit
193endlocal
Note: See TracBrowser for help on using the repository browser.