@echo off

rem ********************************************************************************
rem *
rem * AppsInst.bat
rem *
rem * This file performs all the necessary steps to install applications including
rem * dynamically adding the application installation commands to the Unattend.txt 
rem * file.
rem *
rem * This batch file is called by unattend.bat.
rem *
rem ********************************************************************************


:DIRAGENT
rem ********************************************************************************
rem * Director Agent
rem ********************************************************************************
FOR %%i in (n N) do if %DAINST%==%%i goto CUSTAPPS

             
rem * Create the Director Agent install folder on the client machine
md %NOSDRV%\%APPS_DIR%\diragent

rem * Copy the Director Agent installation files to the client machine.
xcopy %DA_PATH%\*.* %NOSDRV%\%APPS_DIR%\diragent /S
if errorlevel 1 goto COPYERR

rem * Copy the Director Agent installation batch file to the client machine.
copy %TK_PATH%\examples\%NOSDIR%\diragent.bat %NOSDRV%\%APPS_DIR%\diragent
if errorlevel 1 goto COPYERR

rem * Fix director agent CMD.EXE error condition
attrib -r *.*

CLIni.exe %NOSDRV%\%APPS_DIR%\diragent\diragent.rsp /S:Agent /I:RebootIfRequired /V:N
if errorlevel 1 goto DAR_ERR

             
rem * Add the running of the Director Agent setup batch file to the GUIRunOnce.
if %OS_VER%==Win2000Server goto DA_W2K

rem * Windows 2003 installs:  Run DA install BEFORE drivers                                              
CLIni.exe Unattend.ini /S:GuiRunOnce /I:Before Drivers /U:DirAgent /D:,
if errorlevel 1 goto CLERROR
goto DA_CONT
        

:DA_W2K
rem * Windows 2000 installs:  Run DA install AFTER drivers                                              
CLIni.exe Unattend.ini /S:GuiRunOnce /I:After Drivers /U:DirAgent /D:,
if errorlevel 1 goto CLERROR


:DA_CONT
CLIni.exe Unattend.ini /S:GuiRunOnce /I:DirAgent_Command /V:\"CMD.EXE /C C:\Apps\DirAgent\diragent.bat\"
if errorlevel 1 goto CLERROR


:CUSTAPPS
rem ********************************************************************************
rem * Custom Applications
rem ********************************************************************************


goto END


:COPYERR
rem ********************************************************************************
rem * An error occurred copying files.
rem ********************************************************************************
echo An error occurred copying files.
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.
goto ERROR

:DAR_ERR
rem ********************************************************************************
rem * An error occurred updating information in the diragent.rsp file.
rem ********************************************************************************
echo An error occurred adding information to diragent.rsp.
goto ERROR


:ERROR
rem ********************************************************************************
rem * Hit an error in this batch file.
rem ********************************************************************************
echo Encountered an error, stop processing.  Problem in appsinst.bat".
savestat /set2=251 > nul

goto END

:END

