echo -off

if exist SAA.smc then
   mv SAA.smc SAA.efi
endif

if not %1 == "" then
   if not %2 == "" then
      if not %3 == "" then
        goto Check_BIOS
      endif
   endif
endif

echo *******************************************************************************
echo *
echo *  Usage: flash.nsh <BMC Username> <BMC Password> <BIOS Filename>
echo *  
echo *  Please use the BMC account with the administrator privilege!
echo *
echo *******************************************************************************
goto END

:Check_BIOS

if not exist %3 then
   goto No_File
endif

:Flash_BIOS
echo *******************************************************************************
echo *
echo *  Program BIOS and ME regions...
echo *
echo *  The system will REBOOT automatically to complete the BIOS update, after
echo *  uploading the BIOS image to BMC.
echo *
echo *  Press any key to continue, or q or Q to abort.
echo *
echo *******************************************************************************
pause -q

echo *******************************************************************************
echo *
echo *  Start flashing BIOS with BIOS: %3!
echo *  Please do not reboot the system.  Entering SAA...
echo *
echo *******************************************************************************
echo "SAA.efi -I Redfish_HI -u %1 -p %2 -c UpdateBIOS --file %3 --reboot"
SAA.efi -I Redfish_HI -u %1 -p %2 -c UpdateBIOS --file %3 --reboot

goto END

:No_File
echo *******************************************************************************
echo *
echo *  %3 does not exist!  Please verify the filename & try again.
echo *
echo *  Usage: flash.nsh <BMC Username> <BMC Password> <BIOS Filename>
echo *
echo *  Please use BMC account with administrator privilege!
echo *
echo *******************************************************************************

:END
if exist SAA.efi then
   mv SAA.efi SAA.smc
endif
