Untitled
unknown
plain_text
a year ago
12 kB
6
Indexable
::******************************************************************************* ::* ::* Copyright (C) Capgemini Engineering ACT S.A.S 2017-2023. All rights reserved. ::* ::*******************************************************************************/ ::******************************************************************************* ::* ::* Copyright (C) Altran ACT S.A.S. 2019, 2022. All rights reserved. ::* ::******************************************************************************* :: :: :: This script upgrades the current installation to a newer version. :: Usage: :: :: upgrade.cmd [InstallerFile, CorrelationId] :: :: where :: InstallerFile Fully Qualified Pathname of the upgrade installer, required. :: :: CorrelationId is used to generate a log file. :: If not provided, default logfile with name "upgrade.log" is created. :: :: Returns: :: SUCCESS If upgraded successfully :: FAILURE If fails to upgrade :: ::@echo off setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION set InstallerFile=%~1 set correlationId=%~2 set logfileextension=.log set InstallDir=C:\Program Files\IBM\Connect Direct v6.4.0 set productcode={B1A5631E-C84E-40CC-BD64-3D08B4274140} set version=v6.4.0 set nodename=CDW-4624 set FAILURE=1 set SUCCESS=0 set PREUPGRADE_FAILURE=4 set POSTUPGRADE_FAILURE=5 set STATUS=1 :: checking for correlation ID if "%correlationId%"=="" ( set "LOGFILE=upgrade%logfileextension%" set "msilogfile=MSI_upgrade%logfileextension%" ) else ( set "LOGFILE=%correlationId%_upgrade%logfileextension%" set "msilogfile=%correlationId%_MSI_upgrade%logfileextension%" ) set exitStatusFile=%CorrelationId%_ServerUpgradeStatusCode set inifilepath="%InstallDir%\install\downloads\wl_srvr.ini" set preUpgradeStatus=%CorrelationId%_preupgrade_status.txt set preUpgradeScript=pre_upgrade.cmd if not exist "%InstallDir%\install\logs" ( echo %DATE% %TIME% : "%InstallDir%\install\logs" does not exist!! >> "%LOGFILE%" exit %FAILURE% ) cd /D "%InstallDir%\install\logs" :: flush previous status, if one exists if exist "%exitStatusFile%" ( del /f /q "%exitStatusFile%" ) :: check if logfile already exists, if yes append the content, if No create the file if exist "%LOGFILE%" ( echo ############################################################# >> "%LOGFILE%" ) else ( echo ################ %LOGFILE% ################# > "%LOGFILE%" echo %DATE% %TIME% : Creating the log file >> "%LOGFILE%" ) echo %DATE% %TIME% : Installer file name : %InstallerFile% >> "%LOGFILE%" echo %DATE% %TIME% : correlation Id : %correlationId% >> "%LOGFILE%" echo %DATE% %TIME% : log file name : %LOGFILE% >> "%LOGFILE%" echo %DATE% %TIME% : MSI log file name : %msilogfile% >> "%LOGFILE%" set tempUpgradeScriptPath=%TEMP%\upgrade_%RANDOM%.cmd if "%~dp0" == "%InstallDir%\install\scripts\" ( setlocal ENABLEDELAYEDEXPANSION :: Copy upgrade script to temp dir, current file will be ovewritten during upgrade. copy /y "%InstallDir%\install\scripts\upgrade.cmd" "%tempUpgradeScriptPath%" if %ERRORLEVEL% NEQ 0 ( echo %DATE% %TIME% : Error copying upgrade script, Exiting!! >> "%LOGFILE%" echo RC=1 > "%exitStatusFile%" exit %FAILURE% ) :: Execute stopAgent.. cmd /c call "%installDir%\install\agent\bin\stopAgent.cmd" if %ERRORLEVEL% NEQ 0 ( echo %DATE% %TIME% : Error stopping agent, Exiting!! >> "%LOGFILE%" echo RC=1 > "%exitStatusFile%" exit %FAILURE% ) :: flush previous status, if one exists IF EXIST "%InstallDir%\install\logs\%preUpgradeStatus%" ( del /f /q "%InstallDir%\install\logs\%preUpgradeStatus%" ) IF NOT EXIST "%InstallDir%\install\downloads\%preUpgradeScript%" ( setlocal ENABLEDELAYEDEXPANSION echo %DATE% %TIME% : No pre-upgrade script >> "%LOGFILE%" ) ELSE ( SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION echo %DATE% %TIME% : Pre-upgrade script to execute. >> "%LOGFILE%" cmd /c call "%InstallDir%\install\downloads\%preUpgradeScript%" >"%InstallDir%\install\logs\%CorrelationId%_preupgrade_log.txt" IF !ERRORLEVEL! NEQ 0 ( echo %DATE% %TIME% : Pre-upgrade script failed with error !ERRORLEVEL! >> "%LOGFILE%" del /f /q "%InstallDir%\install\downloads\*.cmd" echo RC=%PREUPGRADE_FAILURE% >> "%InstallDir%\install\logs\%preUpgradeStatus%" echo RC=1 >> "%exitStatusFile%" cmd /c call "%installDir%\install\agent\bin\startAgent.cmd" if !ERRORLEVEL! NEQ 0 (echo %DATE% %TIME% : Error starting agent, Exiting!! >> "%LOGFILE%") exit %PREUPGRADE_FAILURE% ) IF !ERRORLEVEL! EQU 0 ( echo RC=0 >> "%InstallDir%\install\logs\%preUpgradeStatus%" ) ) :: Execute upgrade.cmd in this process, don't wait. Suppress user prompts that could hang echo %DATE% %TIME% : Calling upgrade script from temp directory >> "%LOGFILE%" start /min /b call "%tempUpgradeScriptPath%" "%~1" "%~2" exit ) if "%InstallerFile%"=="" ( setlocal ENABLEDELAYEDEXPANSION echo %DATE% %TIME% : Please provide a valid installer filename, exiting !! >> "%LOGFILE%" echo RC=1 > "%exitStatusFile%" del /f /q "%InstallDir%\install\downloads\*.cmd" :: Execute startAgent.. cmd /c call "%installDir%\install\agent\bin\startAgent.cmd" if %ERRORLEVEL% NEQ 0 ( echo %DATE% %TIME% : Error starting agent, Exiting!! >> "%LOGFILE%" ) exit %FAILURE% ) :: Checking if installer exists or not if exist "%InstallerFile%" ( setlocal ENABLEDELAYEDEXPANSION echo %DATE% %TIME% : Installer file exits >> "%LOGFILE%" ) else ( echo %DATE% %TIME% : Installer file doesn't exist, exiting !! >> "%LOGFILE%" echo RC=1 > "%exitStatusFile%" del /f /q "%InstallDir%\install\downloads\*.cmd" :: Execute startAgent.. cmd /c call "%installDir%\install\agent\bin\startAgent.cmd" if %ERRORLEVEL% NEQ 0 ( echo %DATE% %TIME% : Error starting agent, Exiting!! >> "%LOGFILE%" ) exit %FAILURE% ) ::MFT 12199 rem Double all backslashes set FileArg=%InstallerFile:\=\\% rem Check if wmic.exe is in PATH set WMIC= for %%i in (wmic.exe) do set WMIC=%%~$PATH:i if "%WMIC%"=="" ( echo %DATE% %TIME% : Error: wmic.exe not found >> "%LOGFILE%" exit %FAILURE% ) rem Call wmic.exe to get the version number rem which is in the 2 line followed by another line set FileVer= setlocal ENABLEDELAYEDEXPANSION for /f "usebackq skip=1 tokens=1 eol=;" %%i in (`%WMIC% datafile where name^="%FileArg%" get version`) do ( if "!FileVer!"=="" set FileVer=%%i ) ::Extract the VRM from the VRMF returned set folder_version=%FileVer:~0,5% ::Removing last directory from the Install Directory of the base version set FOLDER=%InstallDir% set PARENT= set FOLDER=%FOLDER:~0,-1% for /D %%D in ("%FOLDER%") do ( set "PARENT=%%~dpD" ) set directory=%PARENT%Connect Direct v%folder_version% echo %DATE% %TIME% : directory is %directory% >> "%LOGFILE%" :: Execute backup only in case of minor upgrade if "%version%" EQU "v%folder_version%" ( cmd /c call "%installDir%\install\scripts\backup.cmd" if %ERRORLEVEL% NEQ 0 ( echo %DATE% %TIME% : Error backing up CD, Exiting!! >> "%LOGFILE%" echo RC=1 > "%exitStatusFile%" exit %FAILURE% ) ) "%InstallerFile%" /v"CD_SRC_PRODUCT_CODE=\"%productcode%\" INSTALLDIR=\"%directory%\" CD_AGENT_FLAG=1 /qn /L*V \"%msilogfile%\"" /s /w /clone_wait set RC=%ERRORLEVEL% echo %DATE% %TIME% : error level is : %RC% >> "%LOGFILE%" ::Deleting installer file if exist "%InstallerFile%" ( del /f /q "%InstallerFile%" echo %DATE% %TIME% : Installer file deleted !! >> "%LOGFILE%" ) :: Check for all the success return codes if %RC% EQU 0 set STATUS=0 if %RC% EQU 1641 set STATUS=0 if %RC% EQU 3010 set STATUS=0 if %STATUS% EQU 0 ( echo %DATE% %TIME% : Upgrade done successfully >> "%LOGFILE%" echo RC=0 > "%exitStatusFile%" ) else ( echo %DATE% %TIME% : Error in upgrade, Exiting!! >> "%LOGFILE%" echo RC=1 > "%exitStatusFile%" del /f /q "%InstallDir%\install\downloads\*.cmd" :: Execute startAgent.. cmd /c call "%installDir%\install\agent\bin\startAgent.cmd" exit %FAILURE% ) set postUpgradeStatus=%CorrelationId%_postupgrade_status.txt set postUpgradeScript=post_upgrade.cmd :: flush previous status, if one exists if exist "%InstallDir%\install\logs\%postUpgradeStatus%" ( del /f /q "%InstallDir%\install\logs\%postUpgradeStatus%" ) IF NOT EXIST "%InstallDir%\install\downloads\%postUpgradeScript%" ( setlocal ENABLEDELAYEDEXPANSION echo %DATE% %TIME% : No post-upgrade script >> "%LOGFILE%" ) ELSE ( setlocal ENABLEDELAYEDEXPANSION echo %DATE% %TIME% : Post-upgrade script to executing. >> "%LOGFILE%" cmd /c call "%InstallDir%\install\downloads\%postUpgradeScript%" >"%InstallDir%\install\logs\%CorrelationId%_postupgrade_log.txt" if !ERRORLEVEL! NEQ 0 ( echo %DATE% %TIME% : Post-upgrade script failed with error !ERRORLEVEL!. >> "%LOGFILE%" del /f /q "%InstallDir%\install\downloads\*.cmd" echo RC=%POSTUPGRADE_FAILURE% >"%InstallDir%\install\logs\%postUpgradeStatus%" ) else ( echo %DATE% %TIME% : Post-upgrade script successful. >> "%LOGFILE%" echo RC=0 >"%InstallDir%\install\logs\%postUpgradeStatus%" ) ) :: Create .restoreValidity File set restoreValidityFile="%InstallDir%\install\logs\.restoreValidity" echo "#%date:~0,3% %date:~4,2% %date:~7,2% %time:~0,8%" > %restoreValidityFile% echo previousVersion=true >> %restoreValidityFile% echo currentVersion=true >> %restoreValidityFile% :: Read ifix from registry set "IfixRegKey=HKEY_LOCAL_MACHINE\SOFTWARE\Sterling Commerce\Connect:Direct for Windows NT\%version%\%nodename%\Server Property" for /f "skip=2 tokens=5" %%a in ('reg query "%IfixRegKey%" /v "C:D Fix Level"') do set "ifix=%%a" :: Create prod_version.log File set Version_file="%InstallDir%\install\logs\prod_version.log" echo PRODUCT_BACKUP_VERSION=%FileVer%%ifix% > %Version_file% echo PRODUCT_BACKUP_DATE=%date:~0,3% %date:~4,2% %date:~7,2% %time:~0,8% >> %Version_file% :: Delete pre and post upgrade script if exist. if exist "%InstallDir%\install\downloads\%preUpgradeScript%" ( del /f /q "%InstallDir%\install\downloads\%preUpgradeScript%" echo %DATE% %TIME% : Pre-upgrade script deleted !! >> "%LOGFILE%" ) if exist "%InstallDir%\install\downloads\%postUpgradeScript%" ( del /f /q "%InstallDir%\install\downloads\%postUpgradeScript%" echo %DATE% %TIME% : Post-upgrade script deleted !! >> "%LOGFILE%" ) ::Get the new install directory path to copy MSI log and upgrade status file. find "Property(S): INSTALLDIR" "%msilogfile%" > output.txt FOR /F " tokens=2 delims==" %%A IN (output.txt) DO set "newInstallDir=%%A" for /f "tokens=* delims= " %%a in ("%newInstallDir%") do set newInstallDir=%%a del "%InstallDir%\install\logs\output.txt" /s /f /q copy "%InstallDir%\install\logs\%exitStatusFile%" "%newInstallDir%\install\logs\%exitStatusFile%" if %STATUS% EQU 0 ( ::Delete the content of log directory in case of major upgrade success if NOT "%InstallDir%" EQU "%newInstallDir:~0,-1%" ( :: Delete agent.log as it is already copied and copy all other log files del "%InstallDir%\install\logs\agent.log" /s /f /q xcopy /y /c "%InstallDir%\install\logs\*.log" "%newInstallDir%\install\logs" xcopy /y /c "%InstallDir%\install\logs\*.txt" "%newInstallDir%\install\logs" del "%InstallDir%\install\logs\*.*" /s /f /q echo %DATE% %TIME% : Log Directory Content deleted !! >> "%LOGFILE%" ) ) exit %SUCCESS% endlocal
Editor is loading...
Leave a Comment