@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 ALTAPP
goto GUIRUN

:ALTAPP
rem ********************************************************************************
rem * Choose the Altiris Windows Agent to copy to the target machine
rem ********************************************************************************

if exist %TKDRV%\Agents\AClient\AL7FD4~1.EXE goto ACLI68S
if exist %TKDRV%\Agents\AClient\ALTIRI~3.EXE goto ACLI68
if exist %TKDRV%\aclient.exe goto ACLI65

%TKDRV%\logevent.exe -c:0 -l:1 -ss:"WARNING - Altiris Agent executable not found while running unattend.bat."

goto ALTAPP_E


rem ********************************************************************************
rem * Copy the Altiris 6.5 or earlier Windows agent to the target machine
rem ********************************************************************************
:ACLI65

copy %TKDRV%\aclient.exe %NOSDRV%\%APPS_DIR% > nul
copy %TKDRV%\aclient.inp %NOSDRV%\%APPS_DIR% > nul

:ACLI65_E


rem ********************************************************************************
rem * Copy the Altiris 6.8 Windows agent to the target machine
rem ********************************************************************************
:ACLI68

copy %TKDRV%\Agents\AClient\ALTIRI~3.EXE %NOSDRV%\%APPS_DIR%\aclient.exe > nul
copy %TKDRV%\aclient.inp %NOSDRV%\%APPS_DIR% > nul

:ACLI68_E


rem ********************************************************************************
rem * Copy the Altiris 6.8 SP1 Windows agent to the target machine
rem ********************************************************************************
:ACLI68S

copy %TKDRV%\Agents\AClient\AL7FD4~1.EXE %NOSDRV%\%APPS_DIR%\aclient.exe > nul
copy %TKDRV%\aclient.inp %NOSDRV%\%APPS_DIR% > nul

:ACLI68S_E

:ALTAPP_E

: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




:ALT_TEST
rem ********************************************************************************
rem * NODOSCOPY:
rem * If do not want to copy DOS files to hard drive, uncomment the next line.
rem ********************************************************************************
rem goto ALT_APP2


rem ********************************************************************************
rem * If an Altiris install, jump to setup of Altiris agent, otherwise, remove the
rem * DOS files from the hard drive, post-install.
rem ********************************************************************************
if %DPLY_TYPE% == 4 goto ALT_APP2

rem ********************************************************************************
rem * Non-Altiris install, remove the DOS files from the hard drive, post-install.
rem ********************************************************************************
CLIni.exe Unattend.ini /S:GuiRunOnce /I:Before Drivers /U:RemDOS /D:,

if errorlevel 1 goto CLERROR

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

if errorlevel 1 goto CLERROR

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

if errorlevel 1 goto CLERROR


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

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:EraseIBMBIOCom_Command /V:\"CMD.EXE /C ERASE %NOSDRV%\IBMBIO.COM /q\"

if errorlevel 1 goto CLERROR

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

if errorlevel 1 goto CLERROR


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

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:EraseIBMDOSCom_Command /V:\"CMD.EXE /C ERASE %NOSDRV%\IBMDOS.COM /q\"

if errorlevel 1 goto CLERROR

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

if errorlevel 1 goto CLERROR


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

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:EraseAutoExecBat_Command /V:\"CMD.EXE /C ERASE %NOSDRV%\AUTOEXEC.BAT /q\"

if errorlevel 1 goto CLERROR

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

if errorlevel 1 goto CLERROR


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

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:EraseConfigSys_Command /V:\"CMD.EXE /C ERASE %NOSDRV%\CONFIG.SYS /q\"

if errorlevel 1 goto CLERROR

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

if errorlevel 1 goto CLERROR


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

if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:EraseWinNTLog_Command /V:\"CMD.EXE /C ERASE %NOSDRV%\$WINNT.LOG /q\"

if errorlevel 1 goto CLERROR

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

if errorlevel 1 goto CLERROR


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

if errorlevel 1 goto CLERROR

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

if errorlevel 1 goto CLERROR

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

if errorlevel 1 goto CLERROR


goto RM_WRKDR



: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 %NOSDRV%\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



:RM_WRKDR
rem ********************************************************************************
rem * Common path for cleaning up the %WRK_DIR%
rem ********************************************************************************
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


       
: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 %NOSDRV%\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 %NOSDRV%\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 ********************************************************************************
              
rem ****************************************************************************
rem * Add fix alleviating BSOD when USB keyboard is not attached
rem ****************************************************************************                                     
:KBFIX1
%NOSDRV%
cd \%WRK_DIR%

xcopy %OS_PATH%\i386\txtsetup.sif .

CLIni.exe txtsetup.sif /S:Keyboard /I:kbdhid /T:1 /E:KBENTRY

if errorlevel 1 goto CLERROR
          
call CLIniSet.bat

erase txtsetup.sif          

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

if errorlevel 1 goto CLERROR

set KBENTRY=
                                      
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

