@echo off
rem ********************************************************************************
rem *
rem * CFGFIBRE.BAT
rem *
rem * This file runs the necessary commands to configure a fibre host adapter 
rem * as a boot device using the FIBRECFG.EXE utility.
rem *
rem * The DO_FIBRE environment variable defined and set in usrvars.bat controls
rem * whether this batch file is run or not.
rem *
rem * This batch file is called by runinst.bat.
rem *
rem ********************************************************************************

rem ********************************************************************************
rem * Copy the nvram23.def and nvram22.def to the ram drive and make sure we're 
rem * running from the ram drive.  (This is required for the tool to run.)
rem ********************************************************************************

copy %TK_PATH%\utils\nvram23.def %RAMDSK%\  > nul
copy %TK_PATH%\utils\nvram22.def %RAMDSK%\  > nul
%RAMDSK%
cd \

rem ********************************************************************************
rem * Run the two commands required to configure a fibre host adapter as a 
rem * boot device based on the variables in usrvars.bat. 
rem * 1.)  Enable the adapter BIOS. 
rem * 2.)  Enable selectable boot, and set the first selectable boot device. 
rem ********************************************************************************

fibrecfg.exe /E %FIB_IO%

if errorlevel 1 goto ERROR

fibrecfg.exe /BE0 %FIB_IO% %FIB_WWN% %FIB_LUN%

if errorlevel 1 goto ERROR

:FIBSAVE
rem ********************************************************************************
rem * Write persistent state information that will identify what installation
rem * steps have been completed so far, and control where processing resumes after
rem * the reboot.
rem ********************************************************************************
echo Fibre configuration complete!  Saving status and rebooting server.
savestat.exe /set2=75 > nul

rem ********************************************************************************
rem * Check for errors: SAVESTAT.EXE
rem ********************************************************************************
if not errorlevel 255 goto FREBOOT
echo An error occurred during writing state information.
echo
goto ERROR


:FREBOOT
rem ********************************************************************************
rem * Reboot the system.  Control will return to runinst.bat and processing will
rem * continue.
rem ********************************************************************************
echo Now, reboot the machine

sleep 15
reboot.com
goto END


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

savestat.exe /set2=251 > nul

:END
