1 | @echo off
|
---|
2 |
|
---|
3 | setlocal
|
---|
4 | set testdone=0
|
---|
5 | set target=%1
|
---|
6 | set configfile=%2
|
---|
7 |
|
---|
8 | :: Need to get greenstone installation directory
|
---|
9 | :: set cwd=%CD%
|
---|
10 |
|
---|
11 | set MONITOR_SUCCESS=MAKE SUCCESSFUL
|
---|
12 | set MONITOR_FAILED=MAKE FAILED
|
---|
13 | set MONITOR_FINISHED=MAKE DONE
|
---|
14 |
|
---|
15 | :: check that we have >=1 and <=2 arguments
|
---|
16 | :chkargs
|
---|
17 | if "%target%" == "" goto :usage
|
---|
18 | if not "%3" == "" goto :usage
|
---|
19 | goto begincmd
|
---|
20 |
|
---|
21 |
|
---|
22 | :usage
|
---|
23 | echo.
|
---|
24 | echo Usage: %0 command
|
---|
25 | echo where command is any of the following:
|
---|
26 | echo web-start
|
---|
27 | echo web-stop
|
---|
28 | echo web-restart
|
---|
29 | echo configure-admin
|
---|
30 | echo configure-web [config-filename]
|
---|
31 | echo configure-apache [config-filename]
|
---|
32 | echo configure-cgi
|
---|
33 |
|
---|
34 | ::echo web-status
|
---|
35 | ::echo web-graceful
|
---|
36 | ::echo test-gsdlhome
|
---|
37 | ::echo web-stop-tested
|
---|
38 | echo.
|
---|
39 | goto exit
|
---|
40 |
|
---|
41 |
|
---|
42 | :begincmd
|
---|
43 | :: web-stop-tested command assumes GSDLHOME/greenstone environment is already set
|
---|
44 | if "%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
|
---|
48 | if NOT "%GSDLHOME%" == "" if NOT "%GSDLOS%" == "" goto commands
|
---|
49 | echo.
|
---|
50 | echo Environment variable GSDLHOME (or GSDLOS) 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
|
---|
59 | if "%target%" == "web-start" goto start
|
---|
60 | if "%target%" == "web-stop" goto stop
|
---|
61 | if "%target%" == "web-restart" goto restart
|
---|
62 | if "%target%" == "web-status" goto status
|
---|
63 | if "%target%" == "web-graceful" goto graceful
|
---|
64 | if "%target%" == "configure-admin" goto cfgadmin
|
---|
65 | if "%target%" == "configure-web" goto cfgweb
|
---|
66 | if "%target%" == "configure-apache" goto cfgapach
|
---|
67 | if "%target%" == "configure-cgi" goto cfgcgi
|
---|
68 | if "%target%" == "test-gsdlhome" goto testgsdl
|
---|
69 | if "%target%" == "portcon" goto portcon1
|
---|
70 | :: unknown command
|
---|
71 | goto usage
|
---|
72 |
|
---|
73 | :start
|
---|
74 | :: START starts the app in a new console named by the string following immediately thereafter
|
---|
75 | :: then we start up apache-httpd and pass the signal that the stop command will respond to
|
---|
76 | START "%GSDLHOME%\apachectl" "%GSDLHOME%\bin\windows\starthttpd.exe" GS2_APACHE_HTTPD "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
|
---|
77 | echo %MONITOR_SUCCESS%
|
---|
78 | echo %MONITOR_FINISHED%
|
---|
79 | goto exit
|
---|
80 |
|
---|
81 | :stop
|
---|
82 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD
|
---|
83 | rem if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\apache-httpd\%GSDLOS%\bin\apachectl" stop
|
---|
84 | echo %MONITOR_SUCCESS%
|
---|
85 | echo %MONITOR_FINISHED%
|
---|
86 | goto exit
|
---|
87 |
|
---|
88 | :restart
|
---|
89 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD
|
---|
90 | :: wait 2s, see http://malektips.com/dos0017.html. The 2 in the 2nd line is variable
|
---|
91 | ping 127.0.0.1 -n 2 -w 1000 > nul
|
---|
92 | ping 127.0.0.1 -n 2 -w 1000> nul
|
---|
93 | ::"%GSDLHOME%\bin\windows\starthttpd.exe" GS2_APACHE_HTTPD "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
|
---|
94 | goto start
|
---|
95 |
|
---|
96 | :status
|
---|
97 | :graceful
|
---|
98 | ::echo Command %target% is not yet operational (no local apache web server included in this release).
|
---|
99 | goto exit
|
---|
100 |
|
---|
101 | :stoptest
|
---|
102 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD
|
---|
103 | rem if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\apache-httpd\%GSDLOS%\bin\apachectl" stop
|
---|
104 | goto exit
|
---|
105 |
|
---|
106 | ::configure-web
|
---|
107 | ::configure-cgi
|
---|
108 | :cfgweb
|
---|
109 | :cfgcgi
|
---|
110 | if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg
|
---|
111 | echo Configuring cgi-bin\gsdlsite.cfg
|
---|
112 | set gsdlpath=%GSDLHOME%
|
---|
113 | for /F "delims=*" %%T in ('"echo %gsdlpath%| bin\windows\sed.exe s@\\@\\\\@g"') do set safepath=%%T
|
---|
114 | bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg
|
---|
115 | set gsdlpath=
|
---|
116 | set safepath=
|
---|
117 | goto cgifin
|
---|
118 |
|
---|
119 | :cgimsg
|
---|
120 | echo WARNING: Nothing done for make configure-cgi.
|
---|
121 | echo If you wish to regenerate the file
|
---|
122 | echo %GSDLHOME%\cgi-bin\gsdlsite.cfg
|
---|
123 | echo from scratch, delete the existing file first.
|
---|
124 | echo.
|
---|
125 |
|
---|
126 | :cgifin
|
---|
127 | if "%target%" == "configure-cgi" goto exit
|
---|
128 | if "%target%" == "configure-web" goto cfgapach
|
---|
129 |
|
---|
130 | ::configure-apache
|
---|
131 | :cfgapach
|
---|
132 | if exist "%GSDLHOME%\llssite.cfg" goto :exit
|
---|
133 | if not exist "%GSDLHOME%\llssite.cfg.in" goto :exit
|
---|
134 | copy llssite.cfg.in llssite.cfg
|
---|
135 | set configfile="%GSDLHOME%\llssite.cfg"
|
---|
136 | goto exit
|
---|
137 |
|
---|
138 | ::configure-admin
|
---|
139 | :cfgadmin
|
---|
140 | echo.
|
---|
141 | echo Configuring admin user password:
|
---|
142 | for /F %%T in ('getpw') do set encrypted_password=%%T
|
---|
143 |
|
---|
144 | :: Have to create an intermediate file in the following, because echoing
|
---|
145 | :: lines straight into a pipe adds spaces before the end of each line.
|
---|
146 | :: When piping, need to double-escape the angle brackets with three hat signs,
|
---|
147 | :: but when redirecting to a file, need to escape only once (one hat sign).
|
---|
148 | if ERRORLEVEL 0 (
|
---|
149 | (
|
---|
150 | echo [admin]
|
---|
151 | echo ^<enabled^>true
|
---|
152 | echo ^<groups^>administrator,colbuilder,all-collections-editor
|
---|
153 | echo ^<password^>%encrypted_password%
|
---|
154 | echo ^<username^>admin
|
---|
155 | ) > "%GSDLHOME%\etc\users.txt"
|
---|
156 | type "%GSDLHOME%\etc\users.txt" | txt2db -append "%GSDLHOME%\etc\users.gdb"
|
---|
157 | del "%GSDLHOME%\etc\users.txt"
|
---|
158 | ) else (
|
---|
159 | echo Did not set password
|
---|
160 | )
|
---|
161 | goto exit
|
---|
162 |
|
---|
163 | ::configure-port-and-connection
|
---|
164 | :portcon1
|
---|
165 | set /p port=Enter port number to use:
|
---|
166 | set /p connect=Allow external connections [yes/no]:
|
---|
167 | if "%connect%" == "yes" set allowfrom="all" goto portcon2
|
---|
168 | if "%connect%" == "y" set allowfrom="all" goto portcon2
|
---|
169 | set allowfrom="127.0.0.1"
|
---|
170 |
|
---|
171 | :portcon2
|
---|
172 | if "%port%" == "" goto exit
|
---|
173 | set _sed="bin\windows\sed.exe"
|
---|
174 | set gsdlpath=%GSDLHOME%
|
---|
175 | for /F "delims=*" %%T in ('"echo %gsdlpath%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
|
---|
176 |
|
---|
177 | echo Port: %port%
|
---|
178 | echo Stopping web server (if running)
|
---|
179 | if not exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo missing conf file
|
---|
180 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD SILENT
|
---|
181 | echo Setting config file to use port %port%
|
---|
182 | bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg
|
---|
183 | 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"
|
---|
184 | echo Type '%0 web-start' to start the web server running on port %port%
|
---|
185 | echo Done
|
---|
186 | set port=
|
---|
187 | set connect=
|
---|
188 | set allowfrom=
|
---|
189 | set _sed=
|
---|
190 | set safepath=
|
---|
191 | set gsdlpath=
|
---|
192 |
|
---|
193 |
|
---|
194 | :exit
|
---|
195 | endlocal
|
---|