@echo off

rem ********************************************************************************
rem *
rem * INSTOS.BAT
rem *
rem * This file controls the installation of the RedHat Operating System for the
rem * ServerGuide Scripting Toolkit.
rem *
rem * This batch file is called by the runinst.bat.
rem *
rem ********************************************************************************


:SAVESTAT
rem ********************************************************************************
rem * Clear persistent storage, before continuing.
rem ********************************************************************************
echo Clear persistent, before continuing
savestat.exe /set2=0 > nul

rem ********************************************************************************
rem * Check for errors: SAVESTAT.EXE
rem ********************************************************************************
if not errorlevel 255 goto LLPARAM
echo An error occurred during clearing persistent storage.
echo.
goto ERROR


:LLPARAM
rem ********************************************************************************
rem * Generate the LOADLIN parameter file used in subsequent steps.
rem * This step is necessary because of the DOS command-line
rem * length limitation.
rem ********************************************************************************
echo Generating LOADLIN parameter file (LOADLIN.PAR)
echo %KRL_PATH%\%KRL_FILE% > %RAMDSK%\LOADLIN.PAR
echo /dev/ram rw initrd=%IRD_PATH%\%IRD_FILE% nousbstorage >> %RAMDSK%\LOADLIN.PAR
echo ks=%ANS_URL% >> %RAMDSK%\LOADLIN.PAR

rem ********************************************************************************
rem * If the user provided a RDSK_SZ variable in USRVARS, then add it to the
rem * LOADLIN arameter file.
rem ********************************************************************************
if not "%RDSK_SZ%"=="" echo ramdisk_size=%RDSK_SZ% >> %RAMDSK%\LOADLIN.PAR

rem ********************************************************************************
rem * If the user provided a DPY_NIC variable in USRVARS, then add it to the
rem * LOADLIN parameter file.
rem ********************************************************************************
if not "%DPY_NIC%"=="" echo ksdevice=%DPY_NIC% >> %RAMDSK%\LOADLIN.PAR

rem ********************************************************************************
rem * Check for errors in parameter file creation process
rem ********************************************************************************
if exist %RAMDSK%\LOADLIN.PAR goto LLCHECK
echo An error occurred during LOADLIN parameter file generation.
echo.
goto ERROR

:LLCHECK
rem ********************************************************************************
rem * Begin RedHat Linux installation
rem ********************************************************************************
if exist %LL_PATH%\LOADLIN.EXE goto RM_MEDIA
echo An error occurred during LOADLIN execution.
echo Could not find %LL_PATH%\LOADLIN.EXE.
echo.
goto ERROR

:RM_MEDIA
rem ********************************************************************************
rem * This section controls whether the user is prompted to take out the bootable media
rem * or the altboot program is called to disable the diskette from booting through the
rem * remainder of installation process.   If altboot.exe is called, then the diskette
rem * MUST be restored OUTSIDE this ServerGuide Scripting Toolkit process.
rem ********************************************************************************

rem *********************************************************************
rem * Defines the type of prompting to use during deployment.  
rem * Valid values are: 
rem *   0 - Always prompt the user to remove the boot media. Boot media 
rem *       is unaltered.
rem *   1 - Run altboot.exe to disable a writable boot diskette.  This 
rem *       means the user will not be prompted to remove the boot media, 
rem *       allowing for the complete automation of the installation process.
rem *   2 - Boot media is write protected, user will be prompted to remove 
rem *       the non-writable boot media.  (REQUIRED for bootable CDs)
rem *   3 - Deployment will be via a RSA-II adapter.  Deployment will exit 
rem *       automatically so that the boot media can be unmounted.
rem *   4 - Deployment using Altiris(R).
rem *********************************************************************
if %DPLY_TYPE% == 0 goto ASKUSER
if %DPLY_TYPE% == 1 goto ALTBOOT
if %DPLY_TYPE% == 2 goto ASKUSER
rem if %DPLY_TYPE% == 3 goto VFLOP
if %DPLY_TYPE% == 4 goto ALTSTAT0


:ALTBOOT
rem ********************************************************************************
rem * Run Altboot utility to disable booting from the floppy and boot directly from
rem * the hard drive.
rem ********************************************************************************
echo Running altboot.exe based on variable set in usrvars.bat
altboot.exe /h  > nul
goto DEPLOY

:ASKUSER
rem ********************************************************************************
rem * Ask customer to remove boot diskette, this path will be used when the boot
rem * media is a bootable CDROM, since altboot.exe can NOT alter a non-writable 
rem * media.
rem ********************************************************************************
echo Please remove bootable media at this time.  
pause
goto DEPLOY

rem :FNREBOOT
rem ********************************************************************************
rem * Reboot the machine
rem ********************************************************************************
rem echo Final reboot from ServerGuide Scripting Toolkit
rem %RAMDSK%\reboot.com

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

rem * If doing an Altiris installation, jump to status
if %DPLY_TYPE%==4 goto ALTSTAT1

savestat.exe /set2=251 > nul
goto END

:ALTSTAT0
rem ********************************************************************************
rem Update Altiris with necessary status
rem ********************************************************************************
echo Updating Altiris status: Good
%TKDRV%\logevent.exe -c:0 -l:1 -ss:"INSTOS:  Completed successfully."
goto DEPLOY 

:ALTSTAT1
rem ********************************************************************************
rem Update Altiris with necessary status
rem ********************************************************************************
echo Updating Altiris status: Error
%TKDRV%\logevent.exe -c:251 -l:3 -ss:"INSTOS:  Encountered an error."

rem Reset to root of Toolkit drive
%TKDRV%
cd \

rem Reset persistent storage
savestat.exe /reset > nul
goto END

:DEPLOY
cd %LL_PATH%
%TKDRV%
LOADLIN @%RAMDSK%\LOADLIN.PAR
goto END


:END
