From 5cab9dff7dd5f96b873dbaddce01d235285e8876 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 28 Mar 2024 18:23:30 +0000 Subject: [PATCH] We still need VC Redist on 3007.x --- pkg/windows/msi/Product.wxs | 10 ++ pkg/windows/msi/README-how-to-build.md | 2 + pkg/windows/msi/build_pkg.ps1 | 31 ++++ .../nsis/installer/Salt-Minion-Setup.nsi | 166 ++++++++++++++++++ pkg/windows/nsis/tests/setup.ps1 | 17 +- pkg/windows/prep_salt.ps1 | 24 +++ 6 files changed, 249 insertions(+), 1 deletion(-) diff --git a/pkg/windows/msi/Product.wxs b/pkg/windows/msi/Product.wxs index 9893a32ab0f..121788db9a0 100644 --- a/pkg/windows/msi/Product.wxs +++ b/pkg/windows/msi/Product.wxs @@ -246,6 +246,15 @@ IMCAC - Immediate Custom Action - It's immediate + + + + + + + + + @@ -258,6 +267,7 @@ IMCAC - Immediate Custom Action - It's immediate + diff --git a/pkg/windows/msi/README-how-to-build.md b/pkg/windows/msi/README-how-to-build.md index 34327ba3ab6..1e84dc3a35d 100644 --- a/pkg/windows/msi/README-how-to-build.md +++ b/pkg/windows/msi/README-how-to-build.md @@ -10,6 +10,8 @@ You need - .Net 3.5 SDK (for WiX)* - [Wix 3](http://wixtoolset.org/releases/)** - [Build tools 2015](https://www.microsoft.com/en-US/download/confirmation.aspx?id=48159)** +- Microsoft_VC143_CRT_x64.msm from Visual Studio 2015** +- Microsoft_VC143_CRT_x86.msm from Visual Studio 2015** Notes: - * `build.cmd` will open `optionalfeatures` if necessary. diff --git a/pkg/windows/msi/build_pkg.ps1 b/pkg/windows/msi/build_pkg.ps1 index 15a1778d455..11c531590ea 100644 --- a/pkg/windows/msi/build_pkg.ps1 +++ b/pkg/windows/msi/build_pkg.ps1 @@ -76,6 +76,8 @@ function VerifyOrDownload ($local_file, $URL, $SHA256) { # Script Variables #------------------------------------------------------------------------------- +$WEBCACHE_DIR = "$env:TEMP\msi_build_cache_dir" +$DEPS_URL = "https://repo.saltproject.io/windows/dependencies" $PROJECT_DIR = $(git rev-parse --show-toplevel) $BUILD_DIR = "$PROJECT_DIR\pkg\windows\build" $BUILDENV_DIR = "$PROJECT_DIR\pkg\windows\buildenv" @@ -122,6 +124,21 @@ Write-Host "- Architecture: $BUILD_ARCH" Write-Host "- Salt Version: $Version" Write-Host $("-" * 80) +#------------------------------------------------------------------------------- +# Ensure cache dir exists +#------------------------------------------------------------------------------- + +if ( ! (Test-Path -Path $WEBCACHE_DIR) ) { + Write-Host "Creating cache directory: " -NoNewline + New-Item -ItemType directory -Path $WEBCACHE_DIR | Out-Null + if ( Test-Path -Path $WEBCACHE_DIR ) { + Write-Result "Success" -ForegroundColor Green + } else { + Write-Result "Failed" -ForegroundColor Red + exit 1 + } +} + #------------------------------------------------------------------------------- # Ensure WIX environment variable is set, if not refresh and check again #------------------------------------------------------------------------------- @@ -142,6 +159,19 @@ if ( ! "$env:WIX" ) { } } +#------------------------------------------------------------------------------- +# Caching VC++ Runtimes +#------------------------------------------------------------------------------- + +$RUNTIMES = @( + ("Microsoft_VC143_CRT_x64.msm", "64", "F209B8906063A79B0DFFBB55D3C20AC0A676252DD4F5377CFCD148C409C859EC"), + ("Microsoft_VC143_CRT_x86.msm", "32", "B187BD73C7DC0BA353C5D3A6D9D4E63EF72435F8E68273466F30E5496C1A86F7") +) +$RUNTIMES | ForEach-Object { + $name, $arch, $hash = $_ + VerifyOrDownload "$WEBCACHE_DIR\$name" "$DEPS_URL/$arch/$name" "$hash" +} + #------------------------------------------------------------------------------- # Converting to MSI Version #------------------------------------------------------------------------------- @@ -578,6 +608,7 @@ Push-Location $SCRIPT_DIR -dDisplayVersion="$Version" ` -dInternalVersion="$INTERNAL_VERSION" ` -dDISCOVER_INSTALLDIR="$($DISCOVER_INSTALLDIR[$i])" ` + -dWEBCACHE_DIR="$WEBCACHE_DIR" ` -dDISCOVER_CONFDIR="$DISCOVER_CONFDIR" ` -ext "$($ENV:WIX)bin\WixUtilExtension.dll" ` -ext "$($ENV:WIX)bin\WixUIExtension.dll" ` diff --git a/pkg/windows/nsis/installer/Salt-Minion-Setup.nsi b/pkg/windows/nsis/installer/Salt-Minion-Setup.nsi index 59ca96c76f6..72a66811080 100644 --- a/pkg/windows/nsis/installer/Salt-Minion-Setup.nsi +++ b/pkg/windows/nsis/installer/Salt-Minion-Setup.nsi @@ -524,6 +524,171 @@ InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" "" ShowInstDetails show ShowUnInstDetails show + +Section -copy_prereqs + # Copy prereqs to the Plugins Directory + # These files are downloaded by build_pkg.bat + # This directory gets removed upon completion + SetOutPath "$PLUGINSDIR\" + File /r "..\..\prereqs\" +SectionEnd + +# Check if the Windows 10 Universal C Runtime (KB2999226) is installed. Python +# 3 needs the updated ucrt on Windows 8.1/2012R2 and lower. They are installed +# via KB2999226, but we're not going to patch the system here. Instead, we're +# going to copy the .dll files to the \salt\bin directory +Section -install_ucrt + + Var /GLOBAL UcrtFileName + + # Get the Major.Minor version Number + # Windows 10 introduced CurrentMajorVersionNumber + ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" \ + CurrentMajorVersionNumber + + # Windows 10/2016 will return a value here, skip to the end if returned + StrCmp $R0 '' lbl_needs_ucrt 0 + + # Found Windows 10 + detailPrint "KB2999226 does not apply to this machine" + goto lbl_done + + lbl_needs_ucrt: + # UCRT only needed on Windows Server 2012R2/Windows 8.1 and below. The + # first ReadRegStr command above should have skipped to lbl_done if on + # Windows 10 box + + # Is the update already installed + ClearErrors + + # Use WMI to check if it's installed + detailPrint "Checking for existing UCRT (KB2999226) installation" + nsExec::ExecToStack 'cmd /q /c wmic qfe get hotfixid | findstr "^KB2999226"' + # Clean up the stack + Pop $R0 # Gets the ErrorCode + Pop $R1 # Gets the stdout, which should be KB2999226 if it's installed + + # If it returned KB2999226 it's already installed + StrCmp $R1 'KB2999226' lbl_done + + detailPrint "UCRT (KB2999226) not found" + + # Use RunningX64 here to get the Architecture for the system running the + # installer. + ${If} ${RunningX64} + StrCpy $UcrtFileName "ucrt_x64.zip" + ${Else} + StrCpy $UcrtFileName "ucrt_x86.zip" + ${EndIf} + + ClearErrors + + detailPrint "Unzipping UCRT dll files to $INSTDIR\Scripts" + CreateDirectory $INSTDIR\Scripts + nsisunz::UnzipToLog "$PLUGINSDIR\$UcrtFileName" "$INSTDIR\Scripts" + + # Clean up the stack + Pop $R0 # Get Error + + ${IfNot} $R0 == "success" + detailPrint "error: $R0" + Sleep 3000 + ${Else} + detailPrint "UCRT dll files copied successfully" + ${EndIf} + + lbl_done: + +SectionEnd + + +# Check and install Visual C++ redist 2022 packages +# Hidden section (-) to install VCRedist +Section -install_vcredist_2022 + + Var /GLOBAL VcRedistName + Var /GLOBAL VcRedistReg + + # Only install 64bit VCRedist on 64bit machines + # Use RunningX64 here to get the Architecture for the system running the + # installer. + ${If} ${RunningX64} + StrCpy $VcRedistName "vcredist_x64_2022" + StrCpy $VcRedistReg "SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" + ${Else} + StrCpy $VcRedistName "vcredist_x86_2022" + StrCpy $VcRedistReg "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86" + ${EndIf} + + # Detecting VCRedist Installation + detailPrint "Checking for $VcRedistName..." + ReadRegDword $0 HKLM $VcRedistReg "Installed" + StrCmp $0 "1" +2 0 + Call InstallVCRedist + +SectionEnd + + +Function InstallVCRedist + detailPrint "System requires $VcRedistName" + MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 \ + "$VcRedistName is currently not installed. Would you like to \ + install?" \ + /SD IDYES IDYES InstallVcRedist + + detailPrint "$VcRedistName not installed" + detailPrint ">>>Installation aborted by user<<<" + MessageBox MB_ICONEXCLAMATION \ + "$VcRedistName not installed. Aborted by user.$\n$\n\ + Installer will now close." \ + /SD IDOK + Quit + + InstallVcRedist: + + # If an output variable is specified ($0 in the case below), ExecWait + # sets the variable with the exit code (and only sets the error flag if + # an error occurs; if an error occurs, the contents of the user + # variable are undefined). + # http://nsis.sourceforge.net/Reference/ExecWait + ClearErrors + detailPrint "Installing $VcRedistName..." + ExecWait '"$PLUGINSDIR\$VcRedistName.exe" /install /quiet /norestart' $0 + + IfErrors 0 CheckVcRedistErrorCode + + detailPrint "An error occurred during installation of $VcRedistName" + MessageBox MB_OK|MB_ICONEXCLAMATION \ + "$VcRedistName failed to install. Try installing the package \ + manually.$\n$\n\ + The installer will now close." \ + /SD IDOK + Quit + + CheckVcRedistErrorCode: + # Check for Reboot Error Code (3010) + ${If} $0 == 3010 + detailPrint "$VcRedistName installed but requires a restart to complete." + detailPrint "Reboot and run Salt install again" + MessageBox MB_OK|MB_ICONINFORMATION \ + "$VcRedistName installed but requires a restart to complete." \ + /SD IDOK + + # Check for any other errors + ${ElseIfNot} $0 == 0 + detailPrint "An error occurred during installation of $VcRedistName" + detailPrint "Error: $0" + MessageBox MB_OK|MB_ICONEXCLAMATION \ + "$VcRedistName failed to install. Try installing the package \ + mnually.$\n\ + ErrorCode: $0$\n\ + The installer will now close." \ + /SD IDOK + ${EndIf} + +FunctionEnd + + Section "MainSection" SEC01 ${If} $MoveExistingConfig == 1 @@ -598,6 +763,7 @@ Function .onInit ${EndIf} ${EndIf} + InitPluginsDir Call parseInstallerCommandLineSwitches # Uninstall msi-installed salt diff --git a/pkg/windows/nsis/tests/setup.ps1 b/pkg/windows/nsis/tests/setup.ps1 index c5d8b7459a6..37ca0f74640 100644 --- a/pkg/windows/nsis/tests/setup.ps1 +++ b/pkg/windows/nsis/tests/setup.ps1 @@ -35,6 +35,7 @@ $SCRIPT_DIR = (Get-ChildItem "$($myInvocation.MyCommand.Definition)").Directo $WINDOWS_DIR = "$PROJECT_DIR\pkg\windows" $NSIS_DIR = "$WINDOWS_DIR\nsis" $BUILDENV_DIR = "$WINDOWS_DIR\buildenv" +$PREREQS_DIR = "$WINDOWS_DIR\prereqs" $NSIS_BIN = "$( ${env:ProgramFiles(x86)} )\NSIS\makensis.exe" #------------------------------------------------------------------------------- @@ -49,7 +50,8 @@ Write-Host $("-" * 80) # Setup Directories #------------------------------------------------------------------------------- -$directories = "$BUILDENV_DIR", +$directories = "$PREREQS_DIR", + "$BUILDENV_DIR", "$BUILDENV_DIR\configs" $directories | ForEach-Object { if ( ! (Test-Path -Path "$_") ) { @@ -68,6 +70,19 @@ $directories | ForEach-Object { # Create binaries #------------------------------------------------------------------------------- +$prereq_files = "vcredist_x86_2022.exe", + "vcredist_x64_2022.exe", +$prereq_files | ForEach-Object { + Write-Host "Creating $_`: " -NoNewline + Set-Content -Path "$PREREQS_DIR\$_" -Value "binary" + if ( Test-Path -Path "$PREREQS_DIR\$_" ) { + Write-Result "Success" + } else { + Write-Result "Failed" -ForegroundColor Red + exit 1 + } +} + $binary_files = "ssm.exe", "python.exe" $binary_files | ForEach-Object { diff --git a/pkg/windows/prep_salt.ps1 b/pkg/windows/prep_salt.ps1 index ed3f079713d..a583b17c985 100644 --- a/pkg/windows/prep_salt.ps1 +++ b/pkg/windows/prep_salt.ps1 @@ -62,6 +62,7 @@ if ( $BuildDir ) { } else { $BUILD_DIR = "$SCRIPT_DIR\buildenv" } +$PREREQ_DIR = "$SCRIPT_DIR\prereqs" $SCRIPTS_DIR = "$BUILD_DIR\Scripts" $BUILD_CONF_DIR = "$BUILD_DIR\configs" $SITE_PKGS_DIR = "$BUILD_DIR\Lib\site-packages" @@ -125,6 +126,17 @@ if ( Test-Path -Path $BUILD_CONF_DIR) { } } +if ( Test-Path -Path $PREREQ_DIR ) { + Write-Host "Removing PreReq Directory: " -NoNewline + Remove-Item -Path $PREREQ_DIR -Recurse -Force + if ( ! (Test-Path -Path $PREREQ_DIR) ) { + Write-Result "Success" -ForegroundColor Green + } else { + Write-Result "Failed" -ForegroundColor Red + exit 1 + } +} + #------------------------------------------------------------------------------- # Staging the Build Environment #------------------------------------------------------------------------------- @@ -171,6 +183,18 @@ $scripts | ForEach-Object { } } +# Copy VCRedist 2022 to the prereqs directory +New-Item -Path $PREREQ_DIR -ItemType Directory | Out-Null +Write-Host "Copying VCRedist 2022 $ARCH_X to prereqs: " -NoNewline +$file = "vcredist_$ARCH_X`_2022.exe" +Invoke-WebRequest -Uri "$SALT_DEP_URL/$file" -OutFile "$PREREQ_DIR\$file" +if ( Test-Path -Path "$PREREQ_DIR\$file" ) { + Write-Result "Success" -ForegroundColor Green +} else { + Write-Result "Failed" -ForegroundColor Red + exit 1 +} + #------------------------------------------------------------------------------- # Remove binaries not needed by Salt #-------------------------------------------------------------------------------