[19278] | 1 | @echo off
|
---|
| 2 |
|
---|
[19970] | 3 | setlocal
|
---|
[20262] | 4 | ::set testdone=0
|
---|
[19278] | 5 | set target=%1
|
---|
| 6 | set configfile=%2
|
---|
| 7 |
|
---|
[20262] | 8 | :: Construct the signal using the unique GS2 installation
|
---|
| 9 | :: directory (after replacing colons and backslashes)
|
---|
| 10 | for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@[\\:]@_@g"') do set signal=%%T
|
---|
| 11 | set GS2_APACHE_HTTPD_SIGNAL=GS2_APACHE_HTTPD_%signal%
|
---|
| 12 | rem echo Signal is: %GS2_APACHE_HTTPD_SIGNAL%
|
---|
| 13 |
|
---|
[19970] | 14 | :: Need to get greenstone installation directory
|
---|
| 15 | :: set cwd=%CD%
|
---|
[19278] | 16 |
|
---|
[19970] | 17 | set MONITOR_SUCCESS=MAKE SUCCESSFUL
|
---|
| 18 | set MONITOR_FAILED=MAKE FAILED
|
---|
| 19 | set MONITOR_FINISHED=MAKE DONE
|
---|
| 20 |
|
---|
[19278] | 21 | :: check that we have >=1 and <=2 arguments
|
---|
| 22 | :chkargs
|
---|
[20262] | 23 | if "%target%" == "" goto usage
|
---|
| 24 | if not "%3" == "" goto usage
|
---|
[19278] | 25 | goto begincmd
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | :usage
|
---|
| 29 | echo.
|
---|
| 30 | echo Usage: %0 command
|
---|
| 31 | echo where command is any of the following:
|
---|
[19970] | 32 | echo web-start
|
---|
| 33 | echo web-stop
|
---|
| 34 | echo web-restart
|
---|
[20262] | 35 | ::echo web-status
|
---|
| 36 | ::echo web-graceful
|
---|
[19278] | 37 | echo configure-admin
|
---|
| 38 | echo configure-web [config-filename]
|
---|
| 39 | echo configure-apache [config-filename]
|
---|
| 40 | echo configure-cgi
|
---|
[20262] | 41 | echo test-gsdlhome
|
---|
| 42 | echo web-stop-tested
|
---|
[19278] | 43 | echo.
|
---|
| 44 | goto exit
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | :begincmd
|
---|
| 48 | :: web-stop-tested command assumes GSDLHOME/greenstone environment is already set
|
---|
| 49 | if "%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] | 53 | if 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] | 64 | echo.
|
---|
| 65 | echo Using:
|
---|
| 66 | echo GSDLHOME = %GSDLHOME%
|
---|
| 67 | echo GSDLOS = %GSDLOS%
|
---|
| 68 | echo.
|
---|
| 69 |
|
---|
[19278] | 70 | if "%target%" == "web-start" goto start
|
---|
| 71 | if "%target%" == "web-stop" goto stop
|
---|
| 72 | if "%target%" == "web-restart" goto restart
|
---|
[20262] | 73 | rem if "%target%" == "web-status" goto status
|
---|
| 74 | rem if "%target%" == "web-graceful" goto graceful
|
---|
[19278] | 75 | if "%target%" == "configure-admin" goto cfgadmin
|
---|
| 76 | if "%target%" == "configure-web" goto cfgweb
|
---|
| 77 | if "%target%" == "configure-apache" goto cfgapach
|
---|
| 78 | if "%target%" == "configure-cgi" goto cfgcgi
|
---|
[20262] | 79 | :: already tested gsdlhome (and web-stop-tested) above, don't want to keep looping on it
|
---|
| 80 | if "%target%" == "test-gsdlhome" goto exit
|
---|
| 81 | rem if "%target%" == "web-stop-tested" goto exit
|
---|
[19970] | 82 | if "%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] | 90 | START "%GSDLHOME%\apachectl" "%GSDLHOME%\bin\windows\starthttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
|
---|
[19970] | 91 | echo %MONITOR_SUCCESS%
|
---|
| 92 | echo %MONITOR_FINISHED%
|
---|
| 93 | goto exit
|
---|
| 94 |
|
---|
[19278] | 95 | :stop
|
---|
[20262] | 96 | :stoptest
|
---|
| 97 | if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL%
|
---|
| 98 | if "%target%" == "web-stop-tested" goto exit
|
---|
[19970] | 99 | echo %MONITOR_SUCCESS%
|
---|
[20262] | 100 | echo %MONITOR_FINISHED%
|
---|
[19970] | 101 | goto exit
|
---|
| 102 |
|
---|
[19278] | 103 | :restart
|
---|
[20262] | 104 | if 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] | 106 | ping 127.0.0.1 -n 2 -w 1000 > nul
|
---|
[20262] | 107 | ping 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] | 109 | goto 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] | 114 | goto exit
|
---|
| 115 |
|
---|
| 116 | ::configure-web
|
---|
| 117 | ::configure-cgi
|
---|
| 118 | :cfgweb
|
---|
| 119 | :cfgcgi
|
---|
[19970] | 120 | if 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
|
---|
| 128 | echo WARNING: Nothing done for make configure-cgi.
|
---|
| 129 | echo If you wish to regenerate the file
|
---|
| 130 | echo %GSDLHOME%\cgi-bin\gsdlsite.cfg
|
---|
| 131 | echo from scratch, delete the existing file first.
|
---|
| 132 | echo.
|
---|
| 133 |
|
---|
[19278] | 134 | :cgifin
|
---|
| 135 | if "%target%" == "configure-cgi" goto exit
|
---|
| 136 | if "%target%" == "configure-web" goto cfgapach
|
---|
| 137 |
|
---|
| 138 | ::configure-apache
|
---|
| 139 | :cfgapach
|
---|
[20262] | 140 | if exist "%GSDLHOME%\llssite.cfg" goto exit
|
---|
| 141 | if 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
|
---|
| 148 | echo.
|
---|
[19288] | 149 | echo Configuring admin user password:
|
---|
| 150 | for /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] | 156 | if 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] | 169 | echo.
|
---|
[19288] | 170 | goto exit
|
---|
[19278] | 171 |
|
---|
[19970] | 172 | ::configure-port-and-connection
|
---|
| 173 | :portcon1
|
---|
| 174 | set /p port=Enter port number to use:
|
---|
| 175 | set /p connect=Allow external connections [yes/no]:
|
---|
| 176 | if "%connect%" == "yes" set allowfrom="all" goto portcon2
|
---|
| 177 | if "%connect%" == "y" set allowfrom="all" goto portcon2
|
---|
| 178 | set allowfrom="127.0.0.1"
|
---|
[19288] | 179 |
|
---|
[19970] | 180 | :portcon2
|
---|
[20262] | 181 | if "%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] | 201 | endlocal
|
---|