:: ============================================================================ :: Copyright and license info is available in the LICENSE file included with :: the Server Deployment Package (SDP), and also available online: :: https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE :: ---------------------------------------------------------------------------- :: Parses the ini file :: The name is hardcoded and expected to be ..\..\config\sdp_config.ini from the location of this .bat file! @setlocal enableextensions enabledelayedexpansion @echo off if not x%~1==x ( set SDP_INSTANCE=%~1 goto CheckINI ) if not x%SDP_INSTANCE%==x ( goto CheckINI ) @echo off echo ERROR: Required SDP_INSTANCE value not defined (either as parameter or in environment). echo . exit /b 1 :CheckINI set current_script_dir=%~p0 set ini_file=%current_script_dir%..\..\config\sdp_config.ini if exist %ini_file% ( goto :ParseINI ) @echo off echo ERROR: sdp_config.ini file doesn't exist (%ini_file%) echo . exit /b 1 :ParseINI FOR /F "usebackq" %%i IN (`hostname`) DO SET HOSTNAME=%%i :: Write a batch file to set the env variables - this filename can't be a variable because of endlocal later. echo @echo off> _temp_set.bat set area_found=0 set area=[%SDP_INSTANCE%:%hostname%] set currarea= for /f "usebackq delims=" %%a in ("!ini_file!") do ( set ln=%%a if "x!ln:~0,1!"=="x[" ( set currarea=!ln! ) else ( if not "x!ln:~0,1!"=="x#" ( for /f "tokens=1,2 delims==" %%b in ("!ln!") do ( set currkey=%%b set currval=%%c if /i "x!area!"=="x!currarea!" ( set area_found=1 echo set !currkey!=!currval!>> _temp_set.bat ) ) ) ) ) if %area_found% equ 0 ( Echo Could not find configuration for instance/hostname %area%. Echo . Exit /b 1 ) endlocal :: This must be done after the endlocal call above. call _temp_set.bat :exit