@echo off SETLOCAL EnableExtensions EnableDelayedExpansion REM Copyright 2011-2019 Broadcom. All Rights Reserved. REM The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. REM ///////////////////////////////////////////////////////////////////// REM elxflash.bat REM This script executes elxflash with the requested arguments. REM REM ///////////////////////////////////////////////////////////////////// REM The arguments to pass to elxflash.exe or winlpcfg.exe set arguments=%* REM The executables being called set ELXFLASH_BIN=elxflash.exe set LPCFG_BIN=winlpcfg.exe REM Executable paths set BIN_PATH= REM Boolean set TRUE=1 set FALSE=0 REM This script's exit status set SCRIPT_EXIT_STATUS=0 REM Kit specific vars set KIT_NAME=elxflash REM logfile set LOG_DIR=%SystemDrive%\clu\log set LOG_FILE=elxflash.log set SCRIPT_LOG="%LOG_DIR%\%LOG_FILE%" REM Script location set SCRIPT_DIR=%~dp0 REM The base Image directory used by elxflash set IMAGE_DIR=%~dp0 REM Minimum OS support set MIN_OS_SUP=6.2 REM Error codes set ELXFLASH_ERROR_NOT_ADMIN_USER=8 set ELXFLASH_ERROR_UNSUPPORTED=9 set ELXFLASH_ERROR_MISSING_BIN=21 set LPCFG_ERROR_NOT_ADMIN_USER=78 set LPCFG_ERROR_UNSUPPORTED=71 set LPCFG_ERROR_MISSING_BIN=93 set ERROR_NOT_ADMIN_USER=0 set ERROR_UNSUPPORTED=0 set ERROR_MISSING_BIN=0 REM Emulex OCM Services set MILI_SERVICE="Emulex Management Interface Library v2" set HBAMGR_SERVICE="Emulex HBA Management" set HBADISC_SERVICE="Emulex HBA Discovery" set HBASVCMGR_SERVICE="Emulex SvcMgr" REM Registry Keys set WINPE_KEY="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" set WINPE_REG_FILE="%TEMP%\winpe.reg" set WINPE_TMP_FILE="%TEMP%\winpe.txt" REM The initial status of the Emulex OCM Services set INITIAL_MILI_STATUS=0 set INITIAL_HBAMGR_STATUS=0 set INITIAL_DISCO_STATUS=0 set INITIAL_HBASVC_STATUS=0 REM Set if operating system is WinPE set IS_WINPE_INSTALL=%FALSE% REM do not modify the text below this line set NLM=^ set NL=^^^%NLM%%NLM%^%NLM%%NLM% REM do not modify the text above this line REM REM Begin Script Execution REM call :makeLogDir call :initScriptLog call :setKitSpecificVars call :isOsSupported if not %ERRORLEVEL%==0 set SCRIPT_EXIT_STATUS=%ERRORLEVEL% & goto EXIT call :initArch if not %ERRORLEVEL%==0 set SCRIPT_EXIT_STATUS=%ERRORLEVEL% & goto EXIT call :initBinPath if not %ERRORLEVEL%==0 set SCRIPT_EXIT_STATUS=%ERRORLEVEL% & goto EXIT call :initCluApps if not %ERRORLEVEL%==0 set SCRIPT_EXIT_STATUS=%ERRORLEVEL% & goto EXIT call :isAdminUser if not %ERRORLEVEL%==0 set SCRIPT_EXIT_STATUS=%ERRORLEVEL% & goto EXIT call :isWinPE call :initImageDir call :printLogHeader call :cleanupWindowsServerMILIService REM REM Initialize installation REM call :getElxServicesStatus call :stop_ELX_Services REM REM Execute the clu utility REM :executeCluUtility echo %NL%[Executing CLU Utility] >> %SCRIPT_LOG% if %KIT_NAME%==elxflash ( call :executeElxflash ) else ( call :executeWinLpCfg ) GOTO cleanup REM REM Execute elxflash REM :executeElxflash echo [Executing Elxflash] >> %SCRIPT_LOG% echo "%BIN_PATH%\%ELXFLASH_BIN%" /id="%IMAGE_DIR%" %arguments% >> %SCRIPT_LOG% "%BIN_PATH%\%ELXFLASH_BIN%" /id="%IMAGE_DIR%" %arguments% set SCRIPT_EXIT_STATUS=%ERRORLEVEL% exit /B 0 REM REM Execute winlpcfg REM :executeWinLpCfg echo [Executing WinLpcfg] >> %SCRIPT_LOG% echo "%BIN_PATH%\%LPCFG_BIN%" %arguments% >> %SCRIPT_LOG% "%BIN_PATH%\%LPCFG_BIN%" %arguments% set SCRIPT_EXIT_STATUS=%ERRORLEVEL% exit /B 0 REM REM Clean up REM :cleanup if %IS_WINPE_INSTALL%==%FALSE% call :restoreWindowsServices if %IS_WINPE_INSTALL%==%TRUE% call :restoreWinPEServices GOTO exit REM REM Exit the script. REM :EXIT echo %NL%[EXIT] >> %SCRIPT_LOG% echo %DATE% - %TIME% >> %SCRIPT_LOG% echo Exiting with status = %SCRIPT_EXIT_STATUS% >> %SCRIPT_LOG% REM This should be the last exit. REM Exit the script and unset all variables. exit /B %SCRIPT_EXIT_STATUS% & endlocal REM --------------------------------------------------------------------- REM Function definitions REM --------------------------------------------------------------------- REM ///////////////////////////////////////////////////////////////////// REM Make the log directory if it doesn't exist. REM ///////////////////////////////////////////////////////////////////// :makeLogDir if not exist "%LOG_DIR%" mkdir "%LOG_DIR%" exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Initiliaze a new script log. REM ///////////////////////////////////////////////////////////////////// :initScriptLog echo [initScriptLog] > %SCRIPT_LOG% echo %DATE% - %TIME% >> %SCRIPT_LOG% exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Print the log header. REM ///////////////////////////////////////////////////////////////////// :printLogHeader echo %NL%[printLogHeader] >> %SCRIPT_LOG% echo SCRIPT_LOG = %SCRIPT_LOG% >> %SCRIPT_LOG% echo BIN_PATH = %BIN_PATH% >> %SCRIPT_LOG% echo IMAGE DIR = %IMAGE_DIR% >> %SCRIPT_LOG% echo CLI ARGS = %arguments% >> %SCRIPT_LOG% exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Set kit specific vars. REM ///////////////////////////////////////////////////////////////////// :setKitSpecificVars if %KIT_NAME%==elxflash ( set ERROR_NOT_ADMIN_USER=%ELXFLASH_ERROR_NOT_ADMIN_USER% set ERROR_UNSUPPORTED=%ELXFLASH_ERROR_UNSUPPORTED% set ERROR_MISSING_BIN=%ELXFLASH_ERROR_MISSING_BIN% ) else ( set ERROR_NOT_ADMIN_USER=%LPCFG_ERROR_NOT_ADMIN_USER% set ERROR_UNSUPPORTED=%LPCFG_ERROR_UNSUPPORTED% set ERROR_MISSING_BIN=%LPCFG_ERROR_MISSING_BIN% ) exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Determine if the OS is supported. REM ///////////////////////////////////////////////////////////////////// :isOsSupported echo %NL%[isOsSupported] >> %SCRIPT_LOG% set os_support=6.2 for /f "Tokens=2,*" %%A in ('Reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentVersion ^| findstr REG_SZ') do ( set os_support=%%B ) echo os_support = %os_support% >> %SCRIPT_LOG% if %os_support% LSS %MIN_OS_SUP% exit /B %ERROR_UNSUPPORTED% exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Get the system architecture. REM ///////////////////////////////////////////////////////////////////// :initArch echo %NL%[initArch] >> %SCRIPT_LOG% set CLU_ARCH=NONE set elx_wow64=0 if defined PROCESSOR_ARCHITEW6432 set elx_wow64=1 echo elx_wow64 = %elx_wow64% >> %SCRIPT_LOG% if %PROCESSOR_ARCHITECTURE%==x86 ( if %elx_wow64%==1 ( set CLU_ARCH=x64 ) else ( set CLU_ARCH=win32 ) ) else ( if %PROCESSOR_ARCHITECTURE%==AMD64 set CLU_ARCH=x64 ) echo CLU_ARCH = %CLU_ARCH% >> %SCRIPT_LOG% if "%CLU_ARCH%"=="NONE" exit /B %ERROR_UNSUPPORTED% exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Is this a WinPE installation? REM ///////////////////////////////////////////////////////////////////// :isWinPE echo %NL%[isWinPE] >> %SCRIPT_LOG% set IS_WINPE_INSTALL=%FALSE% echo regedit /E %WINPE_REG_FILE% %WINPE_KEY% >> %SCRIPT_LOG% regedit /E %WINPE_REG_FILE% %WINPE_KEY% find "InstallationType" %WINPE_REG_FILE% > NUL 2>&1 if %ERRORLEVEL%==0 ( echo Found InstallationType registry key! >> %SCRIPT_LOG% type %WINPE_REG_FILE% | find "InstallationType" > %WINPE_TMP_FILE% echo Getting InstallationType... >> %SCRIPT_LOG% set /p INSTALL_TYPE= < %WINPE_TMP_FILE% del %WINPE_TMP_FILE% %WINPE_REG_FILE% > NUL 2>&1 ) else ( del %WINPE_REG_FILE% > NUL 2>&1 echo IS_WINPE_INSTALL = %IS_WINPE_INSTALL% >> %SCRIPT_LOG% exit /B 0 ) REM Get the entire string set INSTALL_TYPE_STR=%INSTALL_TYPE:"InstallationType"=% REM remove the beginning and ending quotes, and replace \\ with \ set INSTALL_TYPE_STR=%INSTALL_TYPE_STR:~1% set INSTALL_TYPE_STR=%INSTALL_TYPE_STR:\\=\% set INSTALL_TYPE_STR=%INSTALL_TYPE_STR:~1,-1% REM Now check if it's WinPE if "%INSTALL_TYPE_STR%"=="WindowsPE" ( set IS_WINPE_INSTALL=%TRUE% ) echo IS_WINPE_INSTALL = %IS_WINPE_INSTALL% >> %SCRIPT_LOG% exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Set the executable path and verify that the path exists. REM ///////////////////////////////////////////////////////////////////// :initBinPath echo %NL%[initBinPath] >> %SCRIPT_LOG% set BIN_PATH=%SCRIPT_DIR%%CLU_ARCH% echo Searching for directory %BIN_PATH% >> %SCRIPT_LOG% if not exist "%BIN_PATH%" exit /B %ERROR_MISSING_BIN% exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Verifies that the executables exists. REM ///////////////////////////////////////////////////////////////////// :initCluApps echo %NL%[initCluApps] >> %SCRIPT_LOG% set BIN_ELXFLASH=%BIN_PATH%\%ELXFLASH_BIN% set BIN_LPCFG=%BIN_PATH%\%LPCFG_BIN% echo Searching for excutable %BIN_ELXFLASH% >> %SCRIPT_LOG% if not exist "%BIN_ELXFLASH%" exit /B %ERROR_MISSING_BIN% echo Searching for excutable %BIN_LPCFG% >> %SCRIPT_LOG% if not exist "%BIN_LPCFG%" exit /B %ERROR_MISSING_BIN% exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Initialize the Image directory path. REM ///////////////////////////////////////////////////////////////////// :initImageDir echo %NL%[Set Image Directory Path] >> %SCRIPT_LOG% set IMAGE_DIR=%SCRIPT_DIR%.. echo IMAGE DIR = %IMAGE_DIR% >> %SCRIPT_LOG% exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Check if the current user is an administrator. REM ///////////////////////////////////////////////////////////////////// :isAdminUser echo %NL%[isAdminUser] >> %SCRIPT_LOG% "%BIN_PATH%\%ELXFLASH_BIN%" /h > NUL if not %ERRORLEVEL%==0 ( echo ERRORLEVEL = %ERROR_NOT_ADMIN_USER% >> %SCRIPT_LOG% echo Not an Adminstrative user! Exiting... >> %SCRIPT_LOG% echo Not an Adminstrative user! Exiting... exit /B %ERROR_NOT_ADMIN_USER% ) else ( exit /B 0 ) REM ///////////////////////////////////////////////////////////////////// REM Save the initial OCM service configuration. REM ///////////////////////////////////////////////////////////////////// :getElxServicesStatus echo %NL%[getElxServicesStatus] >> %SCRIPT_LOG% net start | find "Emulex MILI Management" > NUL if %ERRORLEVEL%==0 set INITIAL_MILI_STATUS=%TRUE% net start | find %HBAMGR_SERVICE% > NUL if %ERRORLEVEL%==0 set INITIAL_HBAMGR_STATUS=%TRUE% net start | find %HBADISC_SERVICE% > NUL if %ERRORLEVEL%==0 set INITIAL_DISCO_STATUS=%TRUE% net start | find %HBASVCMGR_SERVICE% > NUL if %ERRORLEVEL%==0 set INITIAL_HBASVC_STATUS=%TRUE% echo MILI_SERVICE = %INITIAL_MILI_STATUS% >> %SCRIPT_LOG% echo HBAMGR_SERVICE = %INITIAL_HBAMGR_STATUS% >> %SCRIPT_LOG% echo HBADISC_SERVICE = %INITIAL_DISCO_STATUS% >> %SCRIPT_LOG% echo HBASVC_SERVICE = %INITIAL_HBASVC_STATUS% >> %SCRIPT_LOG% exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Stop the services. REM ///////////////////////////////////////////////////////////////////// :stop_ELX_Services echo %NL%[stop_ELX_Services] >> %SCRIPT_LOG% if %INITIAL_HBASVC_STATUS%==%TRUE% call :stop_SVCMGR if %INITIAL_DISCO_STATUS%==%TRUE% call :stop_DISCO if %INITIAL_HBAMGR_STATUS%==%TRUE% call :stop_HBAMGR if %INITIAL_MILI_STATUS%==%TRUE% call :stop_MILI exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Functions used to stop OCM services. REM ///////////////////////////////////////////////////////////////////// :stop_SVCMGR echo %NL%[stop_SVCMGR] >> %SCRIPT_LOG% echo Stopping SVCMGR >> %SCRIPT_LOG% net stop %HBASVCMGR_SERVICE% >> %SCRIPT_LOG% 2>&1 echo SVCMGR_STATUS = %ERRORLEVEL% >> %SCRIPT_LOG% exit /B 0 :stop_DISCO echo %NL%[stop_DISCO] >> %SCRIPT_LOG% echo Stopping DISCO >> %SCRIPT_LOG% net stop %HBADISC_SERVICE% >> %SCRIPT_LOG% 2>&1 echo DISCO_STATUS = %ERRORLEVEL% >> %SCRIPT_LOG% exit /B 0 :stop_HBAMGR echo %NL%[stop_HBAMGR] >> %SCRIPT_LOG% echo Stopping HBAMGR >> %SCRIPT_LOG% net stop %HBAMGR_SERVICE% >> %SCRIPT_LOG% 2>&1 echo HBAMGR_STATUS = %ERRORLEVEL% >> %SCRIPT_LOG% exit /B 0 :stop_MILI echo %NL%[stop_MILI] >> %SCRIPT_LOG% echo Stopping MILI >> %SCRIPT_LOG% net stop %MILI_SERVICE% >> %SCRIPT_LOG% 2>&1 echo MILI_STATUS = %ERRORLEVEL% >> %SCRIPT_LOG% exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Remove the old packaged Windows Server MILI service. REM ///////////////////////////////////////////////////////////////////// :cleanupWindowsServerMILIService echo %NL%[cleanupWindowsServerMILIService] >> %SCRIPT_LOG% set PACKAGED_ELXFLASH_MILI=StandaloneMILIService net start | find "%PACKAGED_ELXFLASH_MILI%" > NUL if %ERRORLEVEL%==0 ( echo net stop %PACKAGED_ELXFLASH_MILI% >> %SCRIPT_LOG% net stop %PACKAGED_ELXFLASH_MILI% >> %SCRIPT_LOG% 2>&1 echo %SystemDrive%\Windows\System32\sc.exe delete %PACKAGED_ELXFLASH_MILI% >> %SCRIPT_LOG% %SystemDrive%\Windows\System32\sc.exe delete %PACKAGED_ELXFLASH_MILI% >> %SCRIPT_LOG% 2>&1 ) exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Restore the initial Windows service configuration. REM ///////////////////////////////////////////////////////////////////// :restoreWindowsServices echo %NL%[restoreWindowsServices] >> %SCRIPT_LOG% REM if %INITIAL_MILI_STATUS%==%TRUE% net start %MILI_SERVICE% >> %SCRIPT_LOG% 2>&1 if %INITIAL_HBAMGR_STATUS%==%TRUE% net start %HBAMGR_SERVICE% >> %SCRIPT_LOG% 2>&1 if %INITIAL_DISCO_STATUS%==%TRUE% net start %HBADISC_SERVICE% >> %SCRIPT_LOG% 2>&1 if %INITIAL_HBASVC_STATUS%==%TRUE% net start %HBASVCMGR_SERVICE% >> %SCRIPT_LOG% 2>&1 REM set ERROR_STAT=%ERRORLEVEL% REM exit /B %ERROR_STAT% exit /B 0 REM ///////////////////////////////////////////////////////////////////// REM Restore the initial WinPE service configuration. REM ///////////////////////////////////////////////////////////////////// :restoreWinPEServices echo %NL%[restoreWinPEServices] >> %SCRIPT_LOG% if %INITIAL_MILI_STATUS%==%TRUE% net start %MILI_SERVICE% >> %SCRIPT_LOG% 2>&1 REM set ERROR_STAT=%ERRORLEVEL% REM exit /B %ERROR_STAT% exit /B 0 :printDebug echo SCRIPT_DIR = %SCRIPT_DIR% echo BIN_PATH = %BIN_PATH% echo INITIAL_MILI_STATUS = %INITIAL_MILI_STATUS% echo INITIAL_HBAMGR_STATUS = %INITIAL_HBAMGR_STATUS% echo INITIAL_DISCO_STATUS = %INITIAL_DISCO_STATUS% exit /B 1