@echo off

rem ********************************************************************************
rem *
rem * GENTXTMD.BAT
rem *
rem * This file dynamically generates the textmode directory for the set of device
rem * drivers copied to the NOS partition by copysgdd.bat for the ServerGuide 
rem * Scripting Toolkit.  
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 * Store the Windows version of the device drivers as an environment variable
rem ********************************************************************************
:SWV
CLIni.exe $oem$\$1\drv\DrvSet.ini /S:Main /I:Windows Version /E:OS_VER

if not errorlevel 1 goto SWV_1
echo An error occurred running clini.exe on $oem$\$1\drv\DrvSet.ini.
echo.
goto ERROR

:SWV_1
call CLIniSet.bat


rem ********************************************************************************
rem *  Custom driver modifications
rem *
rem *  The modifications are only neccessary for driver sets prior to version 7.4.12.
rem ********************************************************************************
:CDRVS
CLIni.exe $oem$\$1\drv\DrvSet.ini /S:Main /I:ServerGuide Version /LT:7.4.12

if errorlevel 100 goto CDRVS_E
if not errorlevel 1 goto CD1
echo An error occurred running clini.exe on $oem$\$1\drv\DrvSet.ini.
echo.
goto ERROR


rem ********************************************************************************
rem *  Custom Driver Modification 1
rem *
rem *  HRSAS and SAS drivers cannot coexist in the unattended install.
rem *  If HostRAID is turned off in the BIOS, then the PCI Ven/Dev ID
rem *  is 9005/043E.  If it is turned on then it is 9005/043F.
rem ********************************************************************************
:CD1
for %%i in (8485,8490,1887,8491,8849) do if "%MACHTYPE%" == "%%i" goto CD1a
goto CD1END

:CD1a

HWDetect.exe /VID:9005 /DID:043E
if errorlevel 1 goto REMHRSAS
goto REMSAS

:REMHRSAS
echo y | deltree $oem$\$1\drv\hrsas > nul
goto CD1END

:REMSAS
echo y | deltree $oem$\$1\drv\sas > nul
goto CD1END

:CD1END

         
rem ********************************************************************************
rem *  Custom Driver Modification 2
rem *
rem *  Windows Server 2003 with SP 1 requires that the custom HAL be
rem *  removed for the 8870 and the SRSATA drivers removed for all systems
rem *  from the driver set prior to installation for all sets previous to 7.4.12.
rem ********************************************************************************
:CD2         
if not "%OS_VER%"=="Win2003Server" goto CD2END

xcopy %OS_PATH%\i386\txtsetup.sif . > nul

CLIni.exe txtsetup.sif /S:Strings /I:spcdname /E:SPCDNAME

if not errorlevel 1 goto CD2a
echo An error occurred running clini.exe on txtsetup.sif.
echo.
goto ERROR

:CD2a
call CLIniset.bat

del txtsetup.sif > nul

if "%SPCDNAME%" == "" goto CD2END

set SPCDNAME=

echo y | deltree $oem$\$1\drv\srsata > nul

for %%i in (8870) do if "%MACHTYPE%" == "%%i" goto REMHAL
goto CD2END

:REMHAL              
echo y | deltree $oem$\$1\drv\hal > nul

:CD2END


rem ********************************************************************************
rem *  Custom Driver Modification 3
rem *
rem *  Activate the chipset drivers if using drivers from ServerGuide 7.4.01 for
rem *  the 7981 for all Win2003 installs.
rem ********************************************************************************
:CD3
if not "%OS_VER%" == "Win2003Server" goto CD3END
for %%i in (7981) do if "%MACHTYPE%" == "%%i" goto CD3-2
goto CD3END

:CD3-2

CLIni.exe $oem$\$1\drv\DrvSet.ini /S:Main /I:ServerGuide Version /=:7.4.01

if errorlevel 100 goto CD3END
if not errorlevel 1 goto CD3-3
echo An error occurred running clini.exe on $oem$\$1\drv\DrvSet.ini.
echo.
goto ERROR

:CD3-3
if not exist $oem$\$1\drv\cs3 mkdir $oem$\$1\drv\cs3 > nul
echo A | xcopy %DSET_PATH%\cs3 $oem$\$1\drv\cs3 /s > nul

CLIni.exe $oem$\$1\drv\cs3\drvinfo.ini /s:Driver Information /i:Supported Systems /u:7981 /d:,

:CD3END


rem ********************************************************************************
rem *  Custom Driver Modification 4
rem *
rem *  Activate the iSCSI drivers for the 8872 if using drivers from
rem *  ServerGuide 7.4.00 for all Win2003 installs.
rem ********************************************************************************
:CD4
if not "%OS_VER%" == "Win2003Server" goto CD4END
for %%i in (8863 8872) do if "%MACHTYPE%" == "%%i" goto CD4-2
goto CD4END

:CD4-2
CLIni.exe $oem$\$1\drv\DrvSet.ini /S:Main /I:ServerGuide Version /=:7.4

if errorlevel 100 goto CD4END
if not errorlevel 1 goto CD4-3
echo An error occurred running clini.exe on $oem$\$1\drv\DrvSet.ini.
echo.
goto ERROR

:CD4-3
if not exist $oem$\$1\drv\is mkdir $oem$\$1\drv\is > nul
if not exist $oem$\$1\drv\iscsi mkdir $oem$\$1\drv\iscsi > nul
echo A | xcopy %DSET_PATH%\is $oem$\$1\drv\is /s > nul
echo A | xcopy %DSET_PATH%\iscsi $oem$\$1\drv\iscsi /s > nul

CLIni.exe $oem$\$1\drv\is\drvinfo.ini /s:Driver Information /i:Supported Systems /u:%MACHTYPE% /d:,

if not errorlevel 1 goto CD4-4
echo An error occurred running clini.exe on $oem$\$1\drv\is\drvinfo.ini.
echo.
goto ERROR

:CD4-4         
CLIni.exe $oem$\$1\drv\iscsi\drvinfo.ini /s:Driver Information /i:Supported Systems /u:%MACHTYPE% /d:,

if not errorlevel 1 goto CD4END
echo An error occurred running clini.exe on $oem$\$1\drv\iscsi\drvinfo.ini.
echo.
goto ERROR

:CD4END

:CDRVS_E

     
rem ********************************************************************************
rem *  Dynamically create the $oem$\textmode directory for this machine type.
rem ********************************************************************************
:DSCAN
if not exist %RAMDSK%\DScan.exe xcopy %TK_PATH%\utils\DScan.exe %RAMDSK% > nul
if not exist %RAMDSK%\savestat.exe xcopy %TK_PATH%\utils\savestat.exe %RAMDSK% > nul

Call tknet.bat DOWN
%NOSDRV%

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

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

rem ********************************************************************************
rem *  Run DScan to dynamically create the $oem$\textmode directory
rem *  for the devices detected in this system.
rem ********************************************************************************
Echo Dynamically create the $oem$\textmode directory for this system.

DScan.exe $OEM$\$1\DRV /T /H:Hwdetect.ini /V:2 /W:%OS_VER%

if not errorlevel 1 goto DSCAN-2
echo An error occurred running dscan.exe.
echo.
goto DERROR

:DSCAN-2

Call tknet.bat UP
%NOSDRV%

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

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

goto END


:DERROR
Call tknet.bat UP
%NOSDRV%

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

savestat.exe /set2=251 > nul

goto END

:END

