@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 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 rem if "%target%" == "web-status" goto status rem if "%target%" == "web-graceful" goto graceful 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 if "%target%" == "portcon" goto portcon1 :: 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" echo %MONITOR_SUCCESS% 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% if "%target%" == "web-stop-tested" goto exit echo %MONITOR_SUCCESS% echo %MONITOR_FINISHED% goto exit :restart if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% :: wait 4s, see http://malektips.com/dos0017.html. The number in the 2nd line is variable (number of seconds to wait) ping 127.0.0.1 -n 2 -w 1000 > nul ping 127.0.0.1 -n 4 -w 1000> nul ::"%GSDLHOME%\bin\windows\starthttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe" goto start :status :graceful ::echo Command %target% is not yet operational (no local apache web server included in this release). 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 make 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 exist "%GSDLHOME%\llssite.cfg" goto exit if not exist "%GSDLHOME%\llssite.cfg.in" goto exit copy llssite.cfg.in llssite.cfg set configfile="%GSDLHOME%\llssite.cfg" 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-port-and-connection :portcon1 set /p port=Enter port number to use: set /p connect=Allow external connections [yes/no]: if "%connect%" == "yes" set allowfrom="all" goto portcon2 if "%connect%" == "y" set allowfrom="all" goto portcon2 set allowfrom="127.0.0.1" :portcon2 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@\*\*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" echo Type '%0 web-start' to start the web server running on port %port% echo Done set port= set connect= set allowfrom= set _sed= set safepath= :exit endlocal