@echo off setlocal ::set testdone=0 set target=%1 set configfile=%2 :: Construct the signal using the unique GS2 installation :: directory (after replacing colons and backslashes) for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@[\\:]@_@g"') do set signal=%%T set GS2_APACHE_HTTPD_SIGNAL=GS2_APACHE_HTTPD_%signal% rem echo Signal is: %GS2_APACHE_HTTPD_SIGNAL% :: Need to get greenstone installation directory :: set cwd=%CD% set MONITOR_SUCCESS=MAKE SUCCESSFUL set MONITOR_FAILED=MAKE FAILED set MONITOR_FINISHED=MAKE DONE :: check that we have >=1 and <=2 arguments :chkargs if "%target%" == "" goto usage if not "%3" == "" goto usage goto begincmd :usage echo. echo Usage: %0 command echo where command is any of the following: echo web-start echo web-stop echo web-restart ::echo web-status ::echo web-graceful echo configure-admin echo configure-web [config-filename] echo configure-apache [config-filename] echo configure-cgi echo set-port echo test-gsdlhome echo web-stop-tested echo. goto exit :begincmd :: web-stop-tested command assumes GSDLHOME/greenstone environment is already set if "%target%" == "web-stop-tested" goto stoptest :: For all other commands, the greenstone environment needs to be set first before they can be run :testgsdl if NOT "%GSDLHOME%" == "" if NOT "%GSDLOS%" == "" goto commands echo. echo Environment variable GSDLHOME (or GSDLOS) not set. echo This needs to be set to run the gsicontrol command %target%. echo Have you run setup.bat? echo. goto exit ::MAIN MENU :commands echo. echo Using: echo GSDLHOME = %GSDLHOME% echo GSDLOS = %GSDLOS% echo. if "%target%" == "web-start" goto start if "%target%" == "web-stop" goto stop if "%target%" == "web-restart" goto restart if "%target%" == "configure-admin" goto cfgadmin if "%target%" == "configure-web" goto cfgweb if "%target%" == "configure-apache" goto cfgapach if "%target%" == "configure-cgi" goto cfgcgi :: already tested gsdlhome (and web-stop-tested) above, don't want to keep looping on it if "%target%" == "test-gsdlhome" goto exit rem if "%target%" == "web-stop-tested" goto exit rem if "%target%" == "web-status" goto status rem if "%target%" == "web-graceful" goto graceful if "%target%" == "set-port" goto setport :: unknown command echo Command unrecognised: %target% goto usage :start :: START starts the app in a new console named by the string following immediately thereafter :: then we start up apache-httpd and pass the signal that the stop command will respond to START "%GSDLHOME%\apachectl" "%GSDLHOME%\bin\windows\starthttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe" :: if the return value is >= 0, it's succeeded: if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%) echo %MONITOR_FINISHED% goto exit :stop :stoptest if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT if "%target%" == "web-stop-tested" goto exit :: if the return value is >= 0, it's succeeded: if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%) echo %MONITOR_FINISHED% goto exit :restart :: Need to stop server, wait and start it again. :: We're using Ping to implement batch file Wait if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% :: Wait 5 seconds and then start. See http://ss64.com/nt/sleep.html (and http://malektips.com/dos0017.html) :: if loopback IP address (127.0.0.1) does not exist, we ask them to manually start it up again ping -n 1 -w 1000 127.0.0.1 |find "TTL=">nul || goto failmsg echo Waiting for re-start.... ping -n 5 -w 1000 127.0.0.1> nul goto start :failmsg echo Unable to wait for restart. Manually run %0 web-start goto exit ::status ::graceful ::echo Command %target% is not operational on this operating system ::goto exit ::configure-admin :cfgadmin echo. echo Configuring admin user password: for /F %%T in ('getpw') do set encrypted_password=%%T :: Have to create an intermediate file in the following, because echoing :: lines straight into a pipe adds spaces before the end of each line. :: When piping, need to double-escape the angle brackets with three hat signs, :: but when redirecting to a file, need to escape only once (one hat sign). if ERRORLEVEL 0 ( ( echo [admin] echo ^true echo ^administrator,colbuilder,all-collections-editor echo ^%encrypted_password% echo ^admin ) > "%GSDLHOME%\etc\users.txt" type "%GSDLHOME%\etc\users.txt" | txt2db -append "%GSDLHOME%\etc\users.gdb" del "%GSDLHOME%\etc\users.txt" ) else ( echo Did not set password ) echo. goto exit ::configure-web ::configure-cgi :cfgweb :cfgcgi if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg echo Configuring cgi-bin\gsdlsite.cfg for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\\\\@g"') do set safepath=%%T bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg set safepath= goto cgifin :cgimsg echo WARNING: Nothing done for configure-cgi. echo If you wish to regenerate the file echo %GSDLHOME%\cgi-bin\gsdlsite.cfg echo from scratch, delete the existing file first. echo. :cgifin if "%target%" == "configure-cgi" goto exit if "%target%" == "configure-web" goto cfgapach ::configure-apache :cfgapach if not "%configfile%" == "" if exist "%configfile%" (goto cfgport) else (echo Config file %configfile% does not exist. Using default llssite.cfg) if exist "%GSDLHOME%\llssite.cfg" ( set configfile="%GSDLHOME%\llssite.cfg" goto cfgport ) if not exist "%GSDLHOME%\llssite.cfg.in" ( echo Unable to proceed as neither %GSDLHOME%\llssite.cfg nor %GSDLHOME%\llssite.cfg.in could be found goto exit ) copy "%GSDLHOME%\llssite.cfg.in" "%GSDLHOME%\llssite.cfg" set configfile="%GSDLHOME%\llssite.cfg" :cfgport echo Configuring the apache webserver... :: See http://ss64.com/nt/for_cmd.html, http://ss64.com/nt/findstr.html (and http://ss64.com/nt/find.html) FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^portnumber %configfile%') do set port=%%G FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^hostIP %configfile%') do set hostIP=%%G FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^externalaccess %configfile%') do set allowfromall=%%G if "%allowfromall%" == "1" set allowfromall="Allow"& goto portcon set allowfromall="Deny" :: Using CALL to jump to labels means we can return from them. BUT need to ensure :: that command extensions are enabled to call labels. So just use GOTO instead. ::http://ss64.com/nt/call.html goto portcon ::configure-port-and-connection :setport set /p port=Enter port number to use: set /p hostIP=Enter host IP to allow (127.0.0.1 is included by default): set /p allowfromall=Allow external connections [yes/no]: if "%allowfromall%" == "yes" set allowfromall="Allow"& goto portcon if "%allowfromall%" == "y" set allowfromall="Allow"& goto portcon set allowfromall="Deny" goto portcon :portcon if "%port%" == "" ( echo Done goto exit ) set _sed="bin\windows\sed.exe" for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T echo Port: %port% echo Stopping web server (if running) if not exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo Missing conf file if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT echo Setting config file to use port %port% type "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf.in" | %_sed% "s@\*\*PORT\*\*@%port%@g" | %_sed% "s@\*\*CONNECTPERMISSION\*\*@%allowfromall%@g" | %_sed% "s@\*\*HOST_IP\*\*@%hostIP%@g" | %_sed% "s@\*\*GSDLHOME\*\*@%safepath%@g" | %_sed% "s@\*\*APACHE_HOME_OS\*\*@%safepath%\/apache-httpd\/%GSDLOS%@g" > "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo Type '%0 web-start' to start the web server running on port %port% echo Done set allowfromall= set _sed= set safepath= set port= :: Extra processing for configure-web and configure-cgi command targets if not "%target%" == "configure-web" if not "%target%" == "configure-cgi" goto exit if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%) echo %MONITOR_FINISHED% goto exit :exit endlocal