@echo off

rem ********************************************************************************
rem *
rem * CKVARS.BAT
rem *
rem * This file checks specific environment variables set in usrvars.bat before
rem * launching the ServerGuide Scripting Toolkit process.  Error messages will be
rem * displayed to the user if a problem is found.
rem *
rem * This batch file is called by the runinst.bat
rem *
rem ********************************************************************************



:CK_NOS
rem ********************************************************************************
rem * Determines which set of checks to run, Windows or Linux.
rem ********************************************************************************
if not %NOSDIR%==windows GOTO CK_LINUX


:CK_WIN
echo Checking Windows specific variables

rem ********************************************************************************
rem * Check 1:   Validates:  %OS_PATH% variable
rem *
rem * Check that the path to the requested operating system is valid by looking for
rem * winnt.exe
rem ********************************************************************************
if not exist %OS_PATH%\i386\winnt.exe goto ERR_WNT

rem ********************************************************************************
rem * Check 2:   Validates:  %ANS_PATH% & %ANS_FILE%
rem *
rem * Check that the path and filename to the Windows unattended installation
rem * file is valid.
rem ********************************************************************************
if not exist %ANS_PATH%\%ANS_FILE%   GOTO ERR_UNAT

rem ********************************************************************************
rem * Check 3:   Validates:  %DA_PATH%
rem *
rem * Check that the path and filename to the Director Agent installation file is
rem * valid (do this ONLY if .
rem ********************************************************************************
FOR %%i in (n N) do if %DAINST% == %%i goto CK_COMP
if not exist %DA_PATH%\diragent.rsp goto ERR_DA


:CK_COMP
rem ********************************************************************************
rem * Check 4:  VALIDATES:  %DSET_PATH%
rem *
rem * Check that the path to the ServerGuide set of device drivers is valid
rem ********************************************************************************
if not exist %DSET_PATH%\DrvSet.ini  goto ERR_SGDD

rem ********************************************************************************
rem * Check 5:   VALIDATES:  Machine type of running target system
rem *
rem * Check that the machine type of the running target system is supported by
rem * the supplied ServerGuide set of device drivers.
rem ********************************************************************************
call compatck.bat

rem ********************************************************************************
rem * Check for errors from compatck.bat
rem ********************************************************************************
savestat.exe /get2 > nul

rem ********************************************************************************
rem * Check for errors: SAVESTAT.EXE
rem ********************************************************************************
FOR %%i in (251 255) do if errorlevel %%i goto STAK_ERR

rem ********************************************************************************
rem * Windows checks are complete, jump to running the rest of the Toolkit process.
rem ********************************************************************************
if %DPLY_TYPE%==4 goto ALTSTAT0

goto DISPVARS



:CK_LINUX
echo Checking Linux specific variables


rem ********************************************************************************
rem * Linux checks are complete, jump to running the rest of the Toolkit process.
rem ********************************************************************************
goto DISPVARS



rem ********************************************************************************
rem * Error messages...
rem ********************************************************************************

:ERR_STUB
rem Clear the screen and display the Toolkit header
call stkhder.bat
echo.
echo An error occurred while checking the RAID configuration file(s).
echo The RAID stub variable (RD_STUB) is empty.  

if not %DPLY_TYPE%==4 goto ERROR 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS:  An error occurred while checking the RAID configuration file(s)."
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS:  The RAID stub variable (RD_STUB) is empty."
goto ERROR

:ERR_RFS
rem Clear the screen and display the Toolkit header
call stkhder.bat
echo.
echo An error occurred while checking the RAID configuration file(s).
echo Unable to locate files: [ RAID path \ stub + (1-16) + .bat or .txt ]
echo    %RD_PATH%\%RD_STUB%(1-16).bat
echo    %RD_PATH%\%RD_STUB%(1-16).txt

if not %DPLY_TYPE%==4 goto ERROR 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS:  An error occurred while checking the RAID configuration file(s)."
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS:  Unable to locate files: [ RAID path \ stub + (1-16) + .bat or .txt ]"
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS:     %RD_PATH%\%RD_STUB%(1-16).bat"
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS:     %RD_PATH%\%RD_STUB%(1-16).txt"
goto ERROR

:ERR_WNT
rem Clear the screen and display the Toolkit header
call stkhder.bat
echo.
echo An error occurred while checking the path to winnt.exe.
echo The following path is invalid: 
echo OS_PATH = %OS_PATH%

if not %DPLY_TYPE%==4 goto ERROR 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS: The following path is invalid:  OS_PATH = %OS_PATH%."
goto ERROR

:ERR_UNAT
rem Clear the screen and display the Toolkit header
call stkhder.bat
echo.
echo An error occurred while checking the path to unattend.txt.   
echo The following path is invalid:
echo %ANS_PATH%\%ANS_FILE%
echo.
echo At least one of the following variables is invalid:  
echo ANS_PATH = %ANS_PATH%
echo ANS_FILE = %ANS_FILE%

if not %DPLY_TYPE%==4 goto ERROR 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS: The following path is invalid:  ANS_PATH\ANS_FILE:" 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS: %ANS_PATH%\%ANS_FILE%" 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS: At least one of the following variables is invalid:" 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS: ANS_PATH = %ANS_PATH%" 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS: ANS_FILE = %ANS_FILE%" 
goto ERROR

:ERR_DA
rem Clear the screen and display the Toolkit header
call stkhder.bat
echo.
echo An error occurred while checking the path to ibmsetup.exe.
echo The following path is invalid: 
echo DA_PATH = %DA_PATH%

if not %DPLY_TYPE%==4 goto ERROR 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS: The following path is invalid:  DA_PATH = %DA_PATH%." 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS: Was unable to locate the file: ibmsetup.exe." 
goto ERROR

:ERR_SGDD
rem Clear the screen and display the Toolkit header
call stkhder.bat
echo.
echo The following path is invalid:  DSET_PATH = %DSET_PATH%
echo Was unable to locate the file:  DrvSet.ini

if not %DPLY_TYPE%==4 goto ERROR 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS: The following path is invalid:  DSET_PATH = %DSET_PATH%." 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS: Was unable to locate the file:  DrvSet.ini." 
goto ERROR

:ERR_DT
rem Clear the screen and display the Toolkit header
call stkhder.bat
echo.
echo An error occurred while checking the deployment type.
echo The following deployment type is invalid: 
echo DPLY_TYPE = %DPLY_TYPE%

if not %DPLY_TYPE%==4 goto ERROR 
%TKDRV%\logevent.exe -c:2 -l:2 -ss:"CKVARS: The following path is invalid:  DPLY_TYPE = %DPLY_TYPE%." 
goto ERROR

:ERROR
rem ********************************************************************************
rem * Hit an error in this batch file.
rem ********************************************************************************
if %DPLY_TYPE%==4 goto STAK_ERR

echo.
echo Please correct the problem by updating the appropriate 
echo variable in the A:\USRVARS.BAT file with a valid value.   
echo Once the appropriate variable has been updated, please 
echo restart the ServerGuide Scripting Toolkit process.
echo.
:STAK_ERR
echo Encountered an error and stopped processing in "ckvars.bat".

if %DPLY_TYPE%==4 goto ALTSTAT1

savestat.exe /set2=251 > nul
goto END


:DISPVARS
rem ********************************************************************************
rem * Display values of specific usrvar.bat variables, to help the customer know
rem * how the deployment process will proceed.
rem ********************************************************************************

rem Clear the screen and display the Toolkit header
call stkhder.bat
echo The Toolkit process is about to begin with the following values:

rem Now, switch to display NOS specific variables
if not %NOSDIR%==windows GOTO LNX_VARS

:WIN_VARS
rem Display usrvars values specific to Windows installation
echo OS_PATH = %OS_PATH% 
echo DSET_PATH = %DSET_PATH%
echo ANS_PATH = %ANS_PATH%
echo ANS_FILE = %ANS_FILE%
echo MACHINE TYPE = %MachType%
echo This machine type is supported by the supplied set of device drivers.
goto TK_VARS

:LNX_VARS
rem Display usrvars values specific to Linux installation
echo OS_PATH = %OS_PATH% 
echo Kernel path\file = %KRL_PATH%\%KRL_FILE%
echo InitRD path\file = %IRD_PATH%\%IRD_FILE%
echo ANS_FILE = %ANS_FILE%
echo ANS_URL = %ANS_URL%
echo LL_PATH = %LL_PATH%
echo DPY_NIC = %DPY_NIC%
goto TK_VARS


:TK_VARS
rem Display basic control variables
echo.
if %DPLY_TYPE% == 1 echo Deployment type = 1 - (Deployment via writable media, run altboot.exe.)
if %DPLY_TYPE% == 2 echo Deployment type = 2 - (Deployment via write-protected media.)
if %DPLY_TYPE% == 3 echo Deployment type = 3 - (Deployment via virtual floppy.)
if %DPLY_TYPE% == 4 echo Deployment type = 4 - (Deployment via Altiris(R) Deployment Solution.)
if %DPLY_TYPE% == 5 echo Deployment type = 5 - (Deployment via Microsoft(R) Automated Deployment Services.)
echo.
echo The ServerGuide Scripting Toolkit will perform the following optional tasks:
echo Perform Updates = %DO_UPDS%
echo Configure RAID = %CFG_RD%

:FIB_TST
rem Fibre configuration ONLY supported for Window installs
if %NOSDIR%==windows goto DISP_FIB
goto DISP_E1

:DISP_FIB
echo Configure Fibre = %DO_FIB%

:DISP_E1
rem ********************************************************************************
rem * Display pause message
rem ********************************************************************************
echo.
echo The screen will pause for 30 seconds before continuing automatically.  
echo Press any key to continue immediately.

sleep.exe 30

rem *** End of page 1 *****

rem ********************************************************************************
rem * Determine optional second screen
rem ********************************************************************************
FOR %%i in (y Y) do if %DO_UPDS% == %%i goto PG2
FOR %%i in (y Y) do if %CFG_RD% == %%i  goto PG2

:FIB_TST
rem Fibre configuration ONLY supported for Window installs
if %NOSDIR%==windows goto CK_FIB
goto RUN_STK

:CK_FIB
FOR %%i in (y Y) do if %DO_FIB% == %%i goto PG2

rem * Nothing to display on the second screen.
goto RUN_STK


:PG2
rem ********************************************************************************
rem * Displaying the optional second screen.
rem ********************************************************************************
call stkhder.bat

rem Display UPDATE information
echo.
echo Perform Updates = %DO_UPDS%
echo Perform BIOS updates = %UPD_BIOS% 
echo Perform ServeRAID updates = %UPD_SR%
echo Path to the BIOS update files = %UPD_PATH%\%UPD_BDIR%
echo Path to the ServeRAID update files = %UPD_PATH%\%UPD_SDIR%

rem Display RAID information
echo.
echo Configure RAID = %CFG_RD%
echo RAID path\file = %RD_PATH%\%RD_FILE%
echo Stop if no policy found = %RD_ERR1%
echo Stop if no RAID controllers found = %RD_ERR2%

:FIB_TST
rem Fibre configuration ONLY supported for Window installs
if %NOSDIR%==windows goto FIB_VARS
goto DISP_E2

:FIB_VARS
rem Display FIBRE information
echo.
echo Configure Fibre = %DO_FIB%
echo Host adapter I/O address = %FIB_IO%
echo Storage device world-wide name = %FIB_WWN%
echo Boot LUN = %FIB_LUN%

goto DISP_E2


:DISP_E2
rem ********************************************************************************
rem * Display pause message
rem ********************************************************************************
echo.
echo The screen will pause for 30 seconds before continuing automatically.
echo Press any key to continue immediately.

sleep.exe 30
goto RUN_STK



:RUN_STK
rem ********************************************************************************
rem * Kick off the ServerGuide Scripting Toolkit process
rem ********************************************************************************
call stkhder.bat
echo.
echo Kick off the ServerGuide Scripting Toolkit process.
goto END



:ALTSTAT0
rem ********************************************************************************
rem * Update Altiris with necessary status
rem ********************************************************************************
echo Updating Altiris status: Good

%TKDRV%\logevent.exe -c:0 -l:1 -ss:"CKVARS: Completed successfully."

rem Reset to root of Toolkit drive
%TKDRV%
cd \

goto END



:ALTSTAT1
rem ********************************************************************************
rem * Update Altiris with necessary status
rem ********************************************************************************
echo Updating Altiris status: Error
%TKDRV%\logevent.exe -c:251 -l:3 -ss:"CKVARS:  Encountered an error."

rem Reset to root of Toolkit drive
%TKDRV%
cd \

rem Reset persistent storage
savestat.exe /reset > nul
goto END


:END
