@echo off

rem ********************************************************************************
rem *
rem * UNATTEND.BAT
rem *
rem * This file performs all the neccessary steps to dynamically add the
rem * hardware specific driver information to the Unattend.txt file.
rem *
rem * This batch file is called by the instos.bat.
rem *
rem ********************************************************************************


rem ********************************************************************************
rem * Change to the target path
rem ********************************************************************************
%NOSDRV%
cd \%WRK_DIR%


rem ********************************************************************************
rem * Generate a blank Unattend.ini file with header information
rem ********************************************************************************
if exist %NOSDRV%\%WRK_DIR%\unattend.ini del %NOSDRV%\%WRK_DIR%\unattend.ini > nul

Unattend.exe /C

if errorlevel 1 goto CUERROR


rem ********************************************************************************
rem * Fill in the required information
rem ********************************************************************************
CLIni.exe Unattend.ini /S:Unattend /I:UnattendTxt /V:%ANS_FILE%

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:Unattend /I:Drivers Path /V:$OEM$\$1\DRV

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:Unattend /I:HWDetectIni /V:Hwdetect.ini

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:Unattend /I:I386 Path /V:%OS_PATH%\i386

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:Unattend /I:Verbose Level /V:2

if errorlevel 1 goto CLERROR


rem * If doing an Altiris installation, jump to custom work
if %DPLY_TYPE% == 4 goto ALT_APP1
goto GUIRUN

:ALT_APP1
rem ********************************************************************************
rem * Copy the Altiris Windows agent to the target machine
rem ********************************************************************************
copy %TKDRV%\aclient.exe %NOSDRV%\%APPS_DIR% > nul
copy %TKDRV%\aclient.inp %NOSDRV%\%APPS_DIR% > nul


:GUIRUN
rem ********************************************************************************
rem * Add the displaying of a message (DrvInst.exe) and
rem * the removal of %NOSDRV%\%WRK_DIR%
rem ********************************************************************************
copy %TK_PATH%\utils\DrvInst.exe > nul


CLIni.exe Unattend.ini /S:GuiRunOnce /I:Before Drivers /U:LaunchDrvInst /D:,

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:LaunchDrvInst_Command /V:\"CMD.EXE /C %NOSDRV%\%WRK_DIR%\DrvInst.exe\"

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:LaunchDrvInst_Supported_Systems /V:All

if errorlevel 1 goto CLERROR


CLIni.exe Unattend.ini /S:GuiRunOnce /I:Before Drivers /U:RemoveWinInst /D:,

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:RemoveWinInst_Command /V:\"CMD.EXE /C RD %NOSDRV%\%WRK_DIR% /s /q\"

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:RemoveWinInst_Supported_Systems /V:All

if errorlevel 1 goto CLERROR


rem * If doing an Altiris installation, jump to custom work
:ALT_TEST
if %DPLY_TYPE% == 4 goto ALT_APP2
goto CUST_APP

:ALT_APP2
rem ********************************************************************************
rem * Add Altiris Windows agent to the unattend.txt
rem ********************************************************************************
CLIni.exe Unattend.ini /S:GuiRunOnce /I:After Drivers /U:DelayAClient /D:,

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:DelayAClient_Command /V:\"CMD.EXE /C C:\Drv\DrvUtils\HoldIt.exe 90\"

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:DelayAClient_Supported_Systems /V:All

if errorlevel 1 goto CLERROR


CLIni.exe Unattend.ini /S:GuiRunOnce /I:After Drivers /U:AClientInst /D:,

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:AClientInst_Command /V:\"CMD.EXE /C

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:AClientInst_Command /A: %NOSDRV%\%APPS_DIR%\aclient.exe %NOSDRV%\%APPS_DIR%\aclient.inp -silent -install\"

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:AClientInst_Supported_Systems /V:All

if errorlevel 1 goto CLERROR

       
:CUST_APP
rem ********************************************************************************
rem * For doing installation of custom application(s)
rem ********************************************************************************
call appsinst.bat

rem ********************************************************************************
rem * Check for errors from GENTXTMD
rem ********************************************************************************
rem echo Checking for errors from gentxtmd
savestat.exe /get2 > nul

rem ********************************************************************************
rem * Check for errors: SAVESTAT.EXE
rem *
rem * The errorlevel here controls the installation process.
rem ********************************************************************************
FOR %%i in (251 255) do if errorlevel %%i goto ERROR

:CHECKOS
rem ********************************************************************************
rem * For Windows 2000 installs only
rem ********************************************************************************
if not %OS_VER%==Win2000Server goto UNATTEND

       
:ADDDELAY
rem ********************************************************************************
rem * Add a 90 second delay to allow driver installations to complete and add
rem * a final reboot.
rem *
rem * Note:  The final reboot will not work for Windows 2003 due to several
rem *        drivers requiring interactive responses from the user.
rem ********************************************************************************
CLIni.exe Unattend.ini /S:GuiRunOnce /I:After Drivers /U:DelayIt /D:,

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:DelayIt_Command /V:\"CMD.EXE /C C:\Drv\DrvUtils\HoldIt.exe 90\"

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:DelayIt_Supported_Systems /V:All

if errorlevel 1 goto CLERROR


CLIni.exe Unattend.ini /S:GuiRunOnce /I:After Drivers /U:RebootIt /D:,

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:RebootIt_Command /V:\"CMD.EXE /C C:\Drv\DrvUtils\Reboot.exe\"

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:RebootIt_Supported_Systems /V:All

if errorlevel 1 goto CLERROR


:UNATTEND
rem ********************************************************************************
rem * Update unattend.txt with hardware specific device driver information
rem ********************************************************************************
echo Running unattend.exe to add driver information to the Unattend.txt file.

Unattend.exe Unattend.ini


rem ********************************************************************************
rem * Check for errors:  UNATTEND.EXE
rem ********************************************************************************
if not errorlevel 1 goto CUSTMODS
echo An error occurred during adding driver info to unattend.txt.
echo.
goto ERROR


:CUSTMODS
rem ********************************************************************************
rem * Update unattend.txt answer file with any required custom modifications
rem ********************************************************************************
if "%MACHTYPE%" == "1883" goto KBFIX1
if "%MACHTYPE%" == "8843" goto KBFIX1
goto END
                         
:KBFIX1

%NOSDRV%
cd \%WRK_DIR%

CLIni.exe %ANS_FILE% /S:KeyBoardDrivers /I:\"USB Keyboard\" /V:\"Retail\"

goto END


:CUERROR
rem ********************************************************************************
rem * An error occurred creating the unattend.ini file.
rem ********************************************************************************
echo An error occurred creating the unattend.ini file.
echo.
goto ERROR


:CLERROR
rem ********************************************************************************
rem * An error occurred adding information to the unattend.ini file.
rem ********************************************************************************
echo An error occurred adding information to unattend.ini.
echo.
goto ERROR


:ERROR
rem ********************************************************************************
rem * Hit an error in this batch file.
rem ********************************************************************************
echo Encountered an error and stopped processing in "unattend.bat".

savestat.exe /set2=251 > nul

goto END

:END

