Changeset 20338

Show
Ignore:
Timestamp:
19.08.2009 17:57:42 (10 years ago)
Author:
ak19
Message:

1. Better not to call EXIT from this batch script after all (since this exits the console too) and won't show the output error messages. Instead, upon an error it merely prints a useful message. 2. Changed some of the lines to not create redundant variables, program runs tidier.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/gsicontrol.bat

    r20262 r20338  
    5252:testgsdl 
    5353if NOT "%GSDLHOME%" == "" if NOT "%GSDLOS%" == "" goto commands 
    54         echo. 
    55     echo Environment variable GSDLHOME (or GSDLOS) not set. 
    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 
     54echo. 
     55echo Environment variable GSDLHOME (or GSDLOS) not set. 
     56echo   This needs to be set to run the gsicontrol command %target%. 
     57echo   Have you run setup.bat? 
     58echo. 
     59goto exit 
    6060 
    6161 
     
    7171if "%target%" == "web-stop" goto stop 
    7272if "%target%" == "web-restart" goto restart 
    73 rem if "%target%" == "web-status" goto status 
    74 rem if "%target%" == "web-graceful" goto graceful 
    7573if "%target%" == "configure-admin" goto cfgadmin 
    7674if "%target%" == "configure-web" goto cfgweb 
     
    8078if "%target%" == "test-gsdlhome" goto exit 
    8179rem if "%target%" == "web-stop-tested" goto exit 
    82 if "%target%" == "portcon" goto portcon1 
    83     :: unknown command 
    84     echo Command unrecognised: %target% 
    85     goto usage 
     80rem if "%target%" == "web-status" goto status 
     81rem if "%target%" == "web-graceful" goto graceful 
     82if "%target%" == "set-port" goto setport 
     83:: unknown command 
     84echo Command unrecognised: %target% 
     85goto usage 
     86 
    8687 
    8788:start 
     
    109110goto start 
    110111 
    111 :status 
    112 :graceful 
    113 ::echo Command %target% is not yet operational (no local apache web server included in this release). 
    114 goto exit 
    115  
    116 ::configure-web 
    117 ::configure-cgi 
    118 :cfgweb 
    119 :cfgcgi 
    120 if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg 
    121     echo Configuring cgi-bin\gsdlsite.cfg 
    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     
    124     set safepath= 
    125     goto cgifin 
    126  
    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  
    134 :cgifin 
    135 if "%target%" == "configure-cgi" goto exit 
    136 if "%target%" == "configure-web" goto cfgapach 
    137  
    138 ::configure-apache 
    139 :cfgapach 
    140 if exist "%GSDLHOME%\llssite.cfg" goto exit  
    141 if not exist "%GSDLHOME%\llssite.cfg.in" goto exit 
    142     copy llssite.cfg.in llssite.cfg 
    143     set configfile="%GSDLHOME%\llssite.cfg" 
    144     goto exit 
     112::status 
     113::graceful 
     114::echo Command %target% is not operational on this operating system 
     115::goto exit 
     116 
    145117 
    146118::configure-admin 
     
    170142goto exit 
    171143 
     144 
     145::configure-web 
     146::configure-cgi 
     147:cfgweb 
     148:cfgcgi 
     149if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg 
     150echo Configuring cgi-bin\gsdlsite.cfg 
     151for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\\\\@g"') do set safepath=%%T 
     152bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg     
     153set safepath= 
     154goto cgifin 
     155 
     156:cgimsg 
     157echo WARNING: Nothing done for configure-cgi. 
     158echo    If you wish to regenerate the file 
     159echo    %GSDLHOME%\cgi-bin\gsdlsite.cfg 
     160echo    from scratch, delete the existing file first. 
     161echo. 
     162 
     163:cgifin 
     164if "%target%" == "configure-cgi" goto exit 
     165if "%target%" == "configure-web" goto cfgapach 
     166 
     167::configure-apache 
     168:cfgapach 
     169if not "%configfile%" == "" if exist "%configfile%" (goto cfgport) else (echo Config file %configfile% does not exist. Using default llssite.cfg) 
     170 
     171if exist "%GSDLHOME%\llssite.cfg" ( 
     172  set configfile="%GSDLHOME%\llssite.cfg" 
     173  goto cfgport  
     174) 
     175if not exist "%GSDLHOME%\llssite.cfg.in" ( 
     176  echo Unable to proceed as neither %GSDLHOME%\llssite.cfg nor %GSDLHOME%\llssite.cfg.in could be found 
     177  goto exit 
     178) 
     179copy "%GSDLHOME%\llssite.cfg.in" "%GSDLHOME%\llssite.cfg" 
     180set configfile="%GSDLHOME%\llssite.cfg" 
     181 
     182:cfgport 
     183echo Configuring the apache webserver... 
     184:: See http://ss64.com/nt/for_cmd.html, http://ss64.com/nt/findstr.html (and http://ss64.com/nt/find.html) 
     185FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^portnumber %configfile%') do set port=%%G 
     186echo Found port %port% 
     187FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^externalaccess %configfile%') do set connect=%%G 
     188if "%connect%" == "1" (set connect=yes) else (set connect=no) 
     189 
     190:: Using CALL to jump to labels means we can return from them. BUT need to ensure 
     191:: that command extensions are enabled to call labels. So just use GOTO instead. 
     192::http://ss64.com/nt/call.html 
     193goto portcon 
     194 
    172195::configure-port-and-connection 
    173 :portcon1 
     196:setport 
    174197set /p port=Enter port number to use: 
    175198set /p connect=Allow external connections [yes/no]: 
     199 
     200:portcon 
    176201if "%connect%" == "yes" set allowfrom="all" goto portcon2 
    177202if "%connect%" == "y" set allowfrom="all" goto portcon2 
    178203set allowfrom="127.0.0.1" 
     204goto portcon2 
    179205 
    180206:portcon2 
    181 if "%port%" == "" echo Done& goto exit 
    182     set _sed="bin\windows\sed.exe" 
    183     for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T 
    184  
    185     echo Port: %port% 
    186     echo Stopping web server (if running) 
    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 
    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% 
     207if "%port%" == "" ( 
    192208    echo Done 
    193     set port= 
    194     set connect= 
    195     set allowfrom= 
    196     set _sed= 
    197     set safepath= 
    198  
     209    goto exit 
     210) 
     211set _sed="bin\windows\sed.exe" 
     212for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T 
     213 
     214echo Port: %port% 
     215echo Stopping web server (if running) 
     216if not exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo Missing conf file 
     217if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT 
     218echo Setting config file to use port %port% 
     219type "%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" 
     220echo Type '%0 web-start' to start the web server running on port %port% 
     221echo Done 
     222 
     223set connect= 
     224set allowfrom= 
     225set _sed= 
     226set safepath= 
     227 
     228:: Extra processing for configure-web and configure-cgi command targets 
     229if not "%target%" == "cfgweb" goto exit 
     230if not "%target%" == "cfgcgi" goto exit 
     231if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%) 
     232echo %MONITOR_FINISHED% 
     233set port= 
     234set externalaccess= 
     235goto exit 
    199236 
    200237:exit 
    201238endlocal 
     239 
     240 
     241