@echo off
setlocal ENABLEDELAYEDEXPANSION

rem  *********************************************************************************
rem  This script file will install QLogic FastLinQ Drivers and upgrade firmware on
rem  QLogic FastLinQ 41000 and 45000 Series adapters. This script will not install 
rem  drivers for QLogic FastLinQ 3400 and 8400 Series adapters.
rem  *********************************************************************************

rem  Update MBI file name wildcard if required.
set  MBI=*MBI*.bin
set  SUCCESS=95
set  QL_ENABLE_PLDM=1

if "%1" == ""               goto install_driver
if /i "%1" == "/?"          goto usage
if /i "%1" == "-help"       goto usage
echo invalid option "%1"
goto :usage

:install_driver
rem Install/Upgrade QLogic FastLinQ Ethernet Driver.
rem Does not downgrade if newer QLogic FastLinQ Ethernet Driver
rem is installed.
if not exist "%~dp0\E4DrvInstaller\setup.exe" goto upgrade_fw
    echo. && echo 579XX Driver installer payload detected. Will attempt to upgrade driver.... 
    start /wait E4DrvInstaller\Setup.exe /s /v"/qn REBOOT=ReallySuppress"
if !errorlevel! neq 0 (
	echo. && echo 579XX Driver update failed. Updating fw with old driver.. 
)

:upgrade_fw
rem Upgrade Firmware on all QLogic FastLinQ Ethernet Devices.
if not exist "%~dp0\winfwnx2.exe" goto missing
if not exist "%~dp0\*MBI*.<bin" goto missing
for %%i in (%MBI%) do (
	call winfwnx2.exe -all upgrade -f -mbi  %%i qlgcrestore
)
goto :exit

:missing
echo Some components required for firmware upgrade are missing. 
echo Please copy the entire package and re-run the batch script.
goto :exit

:usage
echo The script does not require any arguements to run

:exit
set QL_ENABLE_PLDM=
endlocal
@exit /B %ERRORLEVEL%
