source: gsdl/trunk/gsicontrol.bat@ 20262

Last change on this file since 20262 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
RevLine 
[19278]1@echo off
2
[19970]3setlocal
[20262]4::set testdone=0
[19278]5set target=%1
6set configfile=%2
7
[20262]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
[19970]14:: Need to get greenstone installation directory
15:: set cwd=%CD%
[19278]16
[19970]17set MONITOR_SUCCESS=MAKE SUCCESSFUL
18set MONITOR_FAILED=MAKE FAILED
19set MONITOR_FINISHED=MAKE DONE
20
[19278]21:: check that we have >=1 and <=2 arguments
22:chkargs
[20262]23if "%target%" == "" goto usage
24if not "%3" == "" goto usage
[19278]25 goto begincmd
26
27
28:usage
29echo.
30echo Usage: %0 command
31echo where command is any of the following:
[19970]32echo web-start
33echo web-stop
34echo web-restart
[20262]35::echo web-status
36::echo web-graceful
[19278]37echo configure-admin
38echo configure-web [config-filename]
39echo configure-apache [config-filename]
40echo configure-cgi
[20262]41echo test-gsdlhome
42echo web-stop-tested
[19278]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
[20159]53if NOT "%GSDLHOME%" == "" if NOT "%GSDLOS%" == "" goto commands
[19278]54 echo.
[20159]55 echo Environment variable GSDLHOME (or GSDLOS) not set.
[19278]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
[20262]64echo.
65echo Using:
66echo GSDLHOME = %GSDLHOME%
67echo GSDLOS = %GSDLOS%
68echo.
69
[19278]70if "%target%" == "web-start" goto start
71if "%target%" == "web-stop" goto stop
72if "%target%" == "web-restart" goto restart
[20262]73rem if "%target%" == "web-status" goto status
74rem if "%target%" == "web-graceful" goto graceful
[19278]75if "%target%" == "configure-admin" goto cfgadmin
76if "%target%" == "configure-web" goto cfgweb
77if "%target%" == "configure-apache" goto cfgapach
78if "%target%" == "configure-cgi" goto cfgcgi
[20262]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
[19970]82if "%target%" == "portcon" goto portcon1
[19278]83 :: unknown command
[20262]84 echo Command unrecognised: %target%
[19278]85 goto usage
86
87:start
[20159]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
[20262]90START "%GSDLHOME%\apachectl" "%GSDLHOME%\bin\windows\starthttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
[19970]91echo %MONITOR_SUCCESS%
92echo %MONITOR_FINISHED%
93goto exit
94
[19278]95:stop
[20262]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
[19970]99echo %MONITOR_SUCCESS%
[20262]100echo %MONITOR_FINISHED%
[19970]101goto exit
102
[19278]103:restart
[20262]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)
[19970]106ping 127.0.0.1 -n 2 -w 1000 > nul
[20262]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"
[19970]109goto start
110
[19278]111:status
112:graceful
[19970]113::echo Command %target% is not yet operational (no local apache web server included in this release).
[19278]114goto exit
115
116::configure-web
117::configure-cgi
118:cfgweb
119:cfgcgi
[19970]120if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg
[19278]121 echo Configuring cgi-bin\gsdlsite.cfg
[20262]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
[19278]124 set safepath=
[19970]125 goto cgifin
[19278]126
[19970]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
[19278]134:cgifin
135if "%target%" == "configure-cgi" goto exit
136if "%target%" == "configure-web" goto cfgapach
137
138::configure-apache
139:cfgapach
[20262]140if exist "%GSDLHOME%\llssite.cfg" goto exit
141if not exist "%GSDLHOME%\llssite.cfg.in" goto exit
[19278]142 copy llssite.cfg.in llssite.cfg
143 set configfile="%GSDLHOME%\llssite.cfg"
144 goto exit
145
146::configure-admin
147:cfgadmin
148echo.
[19288]149echo Configuring admin user password:
150for /F %%T in ('getpw') do set encrypted_password=%%T
[19290]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.
[19970]154:: When piping, need to double-escape the angle brackets with three hat signs,
[19290]155:: but when redirecting to a file, need to escape only once (one hat sign).
[19288]156if ERRORLEVEL 0 (
157 (
158 echo [admin]
[19290]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"
[19288]166) else (
167 echo Did not set password
168)
[20262]169echo.
[19288]170goto exit
[19278]171
[19970]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"
[19288]179
[19970]180:portcon2
[20262]181if "%port%" == "" echo Done& goto exit
[19970]182 set _sed="bin\windows\sed.exe"
[20262]183 for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
[19970]184
185 echo Port: %port%
186 echo Stopping web server (if running)
[20262]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
[19970]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
[19278]200:exit
[19970]201endlocal
Note: See TracBrowser for help on using the repository browser.