@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 UXSP

echo Copying IBM Director Agent files to target server...
            
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 files to the client machine.
xcopy %TK_PATH%\examples\%NOSDIR%\diragent.bat %NOSDRV%\%APPS_DIR%\diragent\ /Y >nul
if errorlevel 1 goto COPYERR
xcopy %TK_PATH%\examples\%NOSDIR%\dafix.bat %NOSDRV%\%APPS_DIR%\diragent\ /Y >nul
if errorlevel 1 goto COPYERR

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

CLIni.exe %NOSDRV%\%APPS_DIR%\diragent\files\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


:UXSP
rem ********************************************************************************
rem * UpdateXpress System Pack Installer
rem ********************************************************************************

if %DPLY_TYPE%==4 goto UX_ALT_1

rem Loading UXSP environment variables if using a floppy
if not exist %RAMDSK%\TK_VARS.INI goto UX_ERR_1

clini %RAMDSK%\TK_VARS.INI /S:TK_VARS /I:UXSPINST /E:UXSPINST /B:%RAMDSK%\uxsp_var.bat
if errorlevel 1 goto CLERROR
call %RAMDSK%\uxsp_var.bat

clini %RAMDSK%\TK_VARS.INI /S:TK_VARS /I:UXSPPATH /E:UXSPPATH /B:%RAMDSK%\uxsp_var.bat
if errorlevel 1 goto CLERROR
call %RAMDSK%\uxsp_var.bat

clini %RAMDSK%\TK_VARS.INI /S:TK_VARS /I:LOGON    /E:LOGON    /B:%RAMDSK%\uxsp_var.bat
if errorlevel 1 goto CLERROR
call %RAMDSK%\uxsp_var.bat

clini %RAMDSK%\TK_VARS.INI /S:TK_VARS /I:PWD      /E:PWD      /B:%RAMDSK%\uxsp_var.bat
if errorlevel 1 goto CLERROR
call %RAMDSK%\uxsp_var.bat

:UX_ALT_1
if "%UXSPINST%"=="" goto CUSTAPPS
FOR %%i in (n N) do if %UXSPINST%==%%i goto CUSTAPPS
md %NOSDRV%\uxsp
if errorlevel 1 goto UX_ERR_2

echo Processing UpdateXpress System Packs...
echo Copying UXSP environment variables to target system...

echo set LOGON=%LOGON%          >> %NOSDRV%\uxsp\uxspvars.bat
echo set PWD=%PWD%              >> %NOSDRV%\uxsp\uxspvars.bat
echo set UXSPPATH=%UXSPPATH%    >> %NOSDRV%\uxsp\uxspvars.bat

echo Copying batch and vbscript files to target system...

xcopy %TK_PATH%\examples\%NOSDIR%\uxspi.bat %NOSDRV%\uxsp
if errorlevel 1 goto UX_ERR_3
echo -copied uxspi.bat ok

xcopy %TK_PATH%\examples\%NOSDIR%\uxspi.vbs %NOSDRV%\uxsp
if errorlevel 1 goto UX_ERR_4
echo -copied uxspi.vbs ok

rem Gui Run Once.. 
echo Adding UpdateXpress System Packs to Windows GuiRunOnce...
CLIni.exe Unattend.ini /S:GuiRunOnce /I:After Drivers /U:UXSP /D:,
if errorlevel 1 goto CLERROR

CLIni.exe Unattend.ini /S:GuiRunOnce /I:UXSP_Command /V:\"CMD.EXE /C regedit /S C:\uxsp\uxsp.reg\"
if errorlevel 1 goto CLERROR

rem * Add uxsp to registry
echo REGEDIT4 									>  %NOSDRV%\uxsp\uxsp.reg
echo. 										>> %NOSDRV%\uxsp\uxsp.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] 	>> %NOSDRV%\uxsp\uxsp.reg
echo "IBM SGSTK UXSPI"="\"C:\\UXSP\\uxspi.bat\"" 			        >> %NOSDRV%\uxsp\uxsp.reg
echo.										>> %NOSDRV%\uxsp\uxsp.reg

if %DPLY_TYPE%==4 goto UXSP_E
call clrnet.bat

:UXSP_E


: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

:UX_ERR_1
rem ********************************************************************************
rem * An error occurred getting sgtk variables
rem ********************************************************************************
echo %RAMDSK%\TK_VARS.INI not found
goto ERROR

:UX_ERR_2
rem ********************************************************************************
rem * An error occurred creating directory uxsp
rem ********************************************************************************
echo "An error occurred in uxsp creating uxsp directory"
goto ERROR

:UX_ERR_3
rem ********************************************************************************
rem * An error occurred copying uxspi.bat
rem ********************************************************************************
echo "An error occurred in uxsp copying files, "
echo "%TK_PATH%\examples\%NOSDIR%\uxspi.bat %NOSDRV%\uxsp"
goto ERROR

:UX_ERR_4
rem ********************************************************************************
rem * An error occurred copying uxspi.vbs
rem ********************************************************************************
echo "An error occurred in uxsp copying files, "
echo "%TK_PATH%\examples\%NOSDIR%\uxspi.vbs %NOSDRV%\uxsp"
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

