[Windows] Implement installation helpers refactoring (#8865)

* [Windows] Refactor base Installer helper functions

* Fix helper name

* Fix name gen logic and improve error handling

* Fix hash checking logic

* Fix Install-VsixExtension invocation

* Fix variable name in Install-OpenSSL.ps1

* Fix type for git downloadUrl
This commit is contained in:
Vasilii Polikarpov
2023-11-22 15:14:08 +01:00
committed by GitHub
parent 46f21c4413
commit d3e630f774
46 changed files with 361 additions and 462 deletions

View File

@@ -5,26 +5,21 @@
################################################################################ ################################################################################
# Install AWS CLI # Install AWS CLI
Choco-Install -PackageName awscli Install-ChocoPackage awscli
# Install Session Manager Plugin for the AWS CLI # Install Session Manager Plugin for the AWS CLI
$sessionManagerName = "SessionManagerPluginSetup.exe" Install-Binary `
$sessionManagerUrl = "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/windows/$sessionManagerName" -Url "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/windows/SessionManagerPluginSetup.exe" `
$sessionManagerSignatureThumbprint = "FF457E5732E98A9F156E657F8CC7C4432507C3BB" -InstallArgs ("/silent", "/install") `
Install-Binary -Url $sessionManagerUrl -Name $sessionManagerName -ArgumentList ("/silent", "/install") -ExpectedSignature $sessionManagerSignatureThumbprint -ExpectedSignature "FF457E5732E98A9F156E657F8CC7C4432507C3BB"
$env:Path = $env:Path + ";$env:ProgramFiles\Amazon\SessionManagerPlugin\bin" $env:Path = $env:Path + ";$env:ProgramFiles\Amazon\SessionManagerPlugin\bin"
# Install AWS SAM CLI # Install AWS SAM CLI
$packageName = "AWS_SAM_CLI_64_PY3.msi" $packageName = "AWS_SAM_CLI_64_PY3.msi"
$packageUrl = "https://github.com/awslabs/aws-sam-cli/releases/latest/download/$packageName" $packageUrl = "https://github.com/awslabs/aws-sam-cli/releases/latest/download/$packageName"
$packagePath = Start-DownloadWithRetry -Url $packageUrl -Name $packageName
#region Supply chain security - AWS SAM CLI
$fileHash = (Get-FileHash -Path $packagePath -Algorithm SHA256).Hash
$externalHash = Get-HashFromGitHubReleaseBody -RepoOwner "awslabs" -RepoName "aws-sam-cli" -FileName $packageName $externalHash = Get-HashFromGitHubReleaseBody -RepoOwner "awslabs" -RepoName "aws-sam-cli" -FileName $packageName
Use-ChecksumComparison $fileHash $externalHash Install-Binary `
#endregion -Url $packageUrl `
-ExpectedSHA256Sum $externalHash
Install-Binary -FilePath $packagePath
Invoke-PesterTests -TestFile "CLI.Tools" -TestName "AWS" Invoke-PesterTests -TestFile "CLI.Tools" -TestName "AWS"

View File

@@ -8,7 +8,7 @@ Stop-Service -Name w3svc | Out-Null
# Install latest apache in chocolatey # Install latest apache in chocolatey
$installDir = "C:\tools" $installDir = "C:\tools"
Choco-Install -PackageName apache-httpd -ArgumentList "--force", "--params", "/installLocation:$installDir /port:80" Install-ChocoPackage apache-httpd -ArgumentList "--force", "--params", "/installLocation:$installDir /port:80"
# Stop and disable Apache service # Stop and disable Apache service
Stop-Service -Name Apache Stop-Service -Name Apache

View File

@@ -11,9 +11,9 @@ $azureCliConfigPath = 'C:\azureCli'
# make variable to be available in the current session # make variable to be available in the current session
${env:AZURE_CONFIG_DIR} = $azureCliConfigPath ${env:AZURE_CONFIG_DIR} = $azureCliConfigPath
$azCliUrl = 'https://aka.ms/installazurecliwindowsx64' Install-Binary -Type MSI `
$azCliSignatureThumbprint = "72105B6D5F370B62FD5C82F1512F7AD7DEE5F2C0" -Url 'https://aka.ms/installazurecliwindowsx64' `
Install-Binary -Url $azCliUrl -Name 'azure-cli.msi' -ExpectedSignature $azCliSignatureThumbprint -ExpectedSignature '72105B6D5F370B62FD5C82F1512F7AD7DEE5F2C0'
$azureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory' $azureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory'
$null = New-Item -ItemType 'Directory' -Path $azureCliExtensionPath $null = New-Item -ItemType 'Directory' -Path $azureCliExtensionPath

View File

@@ -3,10 +3,8 @@
## Desc: Install Azure CosmosDb Emulator ## Desc: Install Azure CosmosDb Emulator
#################################################################################### ####################################################################################
$InstallerName = "AzureCosmosDBEmulator.msi" Install-Binary -Type MSI `
$InstallerUrl = "https://aka.ms/cosmosdb-emulator" -Url "https://aka.ms/cosmosdb-emulator" `
$SignatureThumbprint = "F372C27F6E052A6BE8BAB3112B465C692196CD6F" -ExpectedSignature "F372C27F6E052A6BE8BAB3112B465C692196CD6F"
Install-Binary -Url $InstallerUrl -Name $InstallerName -ExpectedSignature $SignatureThumbprint
Invoke-PesterTests -TestFile "Tools" -TestName "Azure Cosmos DB Emulator" Invoke-PesterTests -TestFile "Tools" -TestName "Azure Cosmos DB Emulator"

View File

@@ -3,8 +3,8 @@
## Desc: Install Bazel and Bazelisk (A user-friendly launcher for Bazel) ## Desc: Install Bazel and Bazelisk (A user-friendly launcher for Bazel)
################################################################################ ################################################################################
Choco-Install -PackageName bazel Install-ChocoPackage bazel
npm install -g @bazel/bazelisk npm install -g @bazel/bazelisk
Invoke-PesterTests -TestFile "Tools" -TestName "Bazel" Invoke-PesterTests -TestFile "Tools" -TestName "Bazel"

View File

@@ -3,86 +3,29 @@
## Desc: Install BizTalk Project Build Component ## Desc: Install BizTalk Project Build Component
################################################################################ ################################################################################
function Install-Msi $BuildComponentUri = "https://aka.ms/BuildComponentSetup.EN"
{ $BuildComponentSignatureThumbprint = "8740DF4ACB749640AD318E4BE842F72EC651AD80"
<#
.SYNOPSIS
A helper function to install executables.
.DESCRIPTION Write-Host "Downloading BizTalk Project Build Component archive..."
install .exe or .msi binaries from specified Path. $setupZipFile = Start-DownloadWithRetry -Url $BuildComponentUri -Name "BuildComponentSetup.EN.zip"
.PARAMETER MsiPath $setupPath = Join-Path $env:TEMP "BizTalkBuildComponent"
Msi or exe path. Required parameter.
.PARAMETER LogPath
The log file path where installation will write log to. Required parameter.
.EXAMPLE
Install-Msi -MsiPath "c:\temp\abc.msi" -LogPath "c:\abc.log"
#>
Param
(
[Parameter(Mandatory)]
[String] $MsiPath,
[Parameter(Mandatory)]
[String] $LogPath
)
try
{
$filePath = "msiexec.exe"
Write-Host "Starting Install $MsiPath..."
$ArgumentList = ('/i', $MsiPath, '/QN', '/norestart', "/l*v",$LogPath)
$process = Start-Process -FilePath $filePath -ArgumentList $ArgumentList -Wait -PassThru -Verb runAs
$exitCode = $process.ExitCode
if ($exitCode -eq 0 -or $exitCode -eq 3010)
{
Write-Host "Installation for $MsiPath is successful."
}
else
{
Write-Host "Non zero exit code returned by $MsiPath installation process: $exitCode"
Get-Content $LogPath | Write-Host
exit $exitCode
}
}
catch
{
Write-Host "Failed to install $MsiPath : $($_.Exception.Message)"
exit 1
}
}
$bizTalkBuildComponentUri = "https://aka.ms/BuildComponentSetup.EN"
# Download
Write-Host "BizTalk Project Build Component download..."
$setupZipFile = Start-DownloadWithRetry -Url $bizTalkBuildComponentUri -Name "BuildComponentSetup.EN.zip"
# Unzip
$setupPath = "C:\BizTalkBuildComponent"
if (-not (Test-Path -Path $setupPath)) { if (-not (Test-Path -Path $setupPath)) {
$null = New-Item -Path $setupPath -ItemType Directory -Force $null = New-Item -Path $setupPath -ItemType Directory -Force
} }
Write-Host "Unzip $setupZipFile to $setupPath..."
Extract-7Zip -Path $setupZipFile -DestinationPath $setupPath Extract-7Zip -Path $setupZipFile -DestinationPath $setupPath
Write-Host "Installing BizTalk Project Build Component..."
Install-Binary `
-LocalPath "$setupPath\Bootstrap.msi" `
-ExtraInstallArgs ("/l*v", "$setupPath\bootstrap.log") `
-ExpectedSignature $BuildComponentSignatureThumbprint
Install-Binary `
-LocalPath "$setupPath\BuildComponentSetup.msi" `
-ExtraInstallArgs ("/l*v", "$setupPath\buildComponentSetup.log") `
-ExpectedSignature $BuildComponentSignatureThumbprint
Remove-Item $setupZipFile Remove-Item $setupZipFile
# Verify signature
$BuildComponentSignatureThumbprint = "8740DF4ACB749640AD318E4BE842F72EC651AD80"
Test-FileSignature -FilePath "$setupPath\Bootstrap.msi" -ExpectedThumbprint $BuildComponentSignatureThumbprint
Test-FileSignature -FilePath "$setupPath\BuildComponentSetup.msi" -ExpectedThumbprint $BuildComponentSignatureThumbprint
# Install
Install-Msi -MsiPath "$setupPath\Bootstrap.msi" -LogPath "$setupPath\bootstrap.log"
Install-Msi -MsiPath "$setupPath\BuildComponentSetup.msi" -LogPath "$setupPath\buildComponentSetup.log"
Remove-Item $setupPath -Recurse -Force Remove-Item $setupPath -Recurse -Force
# Test
Invoke-PesterTests -TestFile "BizTalk" -TestName "BizTalk Build Component Setup" Invoke-PesterTests -TestFile "BizTalk" -TestName "BizTalk Build Component Setup"

View File

@@ -6,7 +6,7 @@
$commonPackages = (Get-ToolsetContent).choco.common_packages $commonPackages = (Get-ToolsetContent).choco.common_packages
foreach ($package in $commonPackages) { foreach ($package in $commonPackages) {
Choco-Install -PackageName $package.name -ArgumentList $package.args Install-ChocoPackage $package.name -ArgumentList $package.args
} }
Invoke-PesterTests -TestFile "ChocoPackages" Invoke-PesterTests -TestFile "ChocoPackages"

View File

@@ -4,10 +4,9 @@
################################################################################ ################################################################################
# Download and install latest Chrome browser # Download and install latest Chrome browser
$ChromeSignatureThumbprint = "2673EA6CC23BEFFDA49AC715B121544098A1284C" Install-Binary `
$ChromeInstallerFile = "googlechromestandaloneenterprise64.msi" -Url 'https://dl.google.com/tag/s/dl/chrome/install/googlechromestandaloneenterprise64.msi' `
$ChromeInstallerUrl = "https://dl.google.com/tag/s/dl/chrome/install/${ChromeInstallerFile}" -ExpectedSignature '2673EA6CC23BEFFDA49AC715B121544098A1284C'
Install-Binary -Url $ChromeInstallerUrl -Name $ChromeInstallerFile -ArgumentList @() -ExpectedSignature $ChromeSignatureThumbprint
# Prepare firewall rules # Prepare firewall rules
Write-Host "Adding the firewall rule for Google update blocking..." Write-Host "Adding the firewall rule for Google update blocking..."

View File

@@ -3,10 +3,8 @@
## Desc: Install SQL Server® Data-Tier Application Framework (DacFx) for Windows ## Desc: Install SQL Server® Data-Tier Application Framework (DacFx) for Windows
#################################################################################### ####################################################################################
$InstallerName = "DacFramework.msi" Install-Binary -Type MSI `
$InstallerUrl = "https://aka.ms/dacfx-msi" -Url 'https://aka.ms/dacfx-msi' `
$SignatureThumbprint = "72105B6D5F370B62FD5C82F1512F7AD7DEE5F2C0" -ExpectedSignature '72105B6D5F370B62FD5C82F1512F7AD7DEE5F2C0'
Install-Binary -Url $InstallerUrl -Name $InstallerName -ExpectedSignature $SignatureThumbprint
Invoke-PesterTests -TestFile "Tools" -TestName "DACFx" Invoke-PesterTests -TestFile "Tools" -TestName "DACFx"

View File

@@ -5,8 +5,8 @@
################################################################################ ################################################################################
Write-Host "Install-Package Docker-Compose v1" Write-Host "Install-Package Docker-Compose v1"
$versionToInstall = Get-LatestChocoPackageVersion -TargetVersion "1.29" -PackageName "docker-compose" $versionToInstall = Resolve-ChocoPackageVersion -PackageName "docker-compose" -TargetVersion "1.29"
Choco-Install -PackageName docker-compose -ArgumentList "--version=$versionToInstall" Install-ChocoPackage docker-compose -ArgumentList "--version=$versionToInstall"
Write-Host "Install-Package Docker-Compose v2" Write-Host "Install-Package Docker-Compose v2"
$dockerComposev2Url = "https://github.com/docker/compose/releases/latest/download/docker-compose-windows-x86_64.exe" $dockerComposev2Url = "https://github.com/docker/compose/releases/latest/download/docker-compose-windows-x86_64.exe"

View File

@@ -5,19 +5,18 @@
################################################################################ ################################################################################
# Install and configure Firefox browser # Install and configure Firefox browser
Write-Host "Install latest Firefox browser..." Write-Host "Get the latest Firefox version..."
$VersionsManifest = Invoke-RestMethod "https://product-details.mozilla.org/1.0/firefox_versions.json" $VersionsManifest = Invoke-RestMethod "https://product-details.mozilla.org/1.0/firefox_versions.json"
$InstallerUrl = "https://download.mozilla.org/?product=firefox-$($VersionsManifest.LATEST_FIREFOX_VERSION)&os=win64&lang=en-US"
$packagePath = Start-DownloadWithRetry -Url $InstallerUrl -Name "FirefoxSetup.exe"
#region Supply chain security - Stack Write-Host "Install Firefox browser..."
$fileHash = (Get-FileHash -Path $packagePath -Algorithm SHA256).Hash $installerUrl = "https://download.mozilla.org/?product=firefox-$($VersionsManifest.LATEST_FIREFOX_VERSION)&os=win64&lang=en-US"
$hashUrl = "https://archive.mozilla.org/pub/firefox/releases/$($VersionsManifest.LATEST_FIREFOX_VERSION)/SHA256SUMS" $hashUrl = "https://archive.mozilla.org/pub/firefox/releases/$($VersionsManifest.LATEST_FIREFOX_VERSION)/SHA256SUMS"
$externalHash = (Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*win64/en-US/Firefox Setup*exe*" }).Split(' ')[0] $externalHash = (Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*win64/en-US/Firefox Setup*exe*" }).Split(' ')[0]
Use-ChecksumComparison $fileHash $externalHash
#endregion
Install-Binary -FilePath $packagePath -ArgumentList "/silent", "/install" Install-Binary -Type EXE `
-Url $installerUrl `
-InstallArgs @("/silent", "/install") `
-ExpectedSHA256Sum $externalHash
Write-Host "Disable autoupdate..." Write-Host "Disable autoupdate..."
$FirefoxDirectoryPath = Join-Path $env:ProgramFiles "Mozilla Firefox" $FirefoxDirectoryPath = Join-Path $env:ProgramFiles "Mozilla Firefox"
@@ -32,8 +31,7 @@ pref("general.config.filename", "mozilla.cfg");' -ItemType file -force
# Download and install Gecko WebDriver # Download and install Gecko WebDriver
Write-Host "Install Gecko WebDriver..." Write-Host "Install Gecko WebDriver..."
$GeckoDriverPath = "$($env:SystemDrive)\SeleniumWebDrivers\GeckoDriver" $GeckoDriverPath = "$($env:SystemDrive)\SeleniumWebDrivers\GeckoDriver"
if (-not (Test-Path -Path $GeckoDriverPath)) if (-not (Test-Path -Path $GeckoDriverPath)) {
{
New-Item -Path $GeckoDriverPath -ItemType Directory -Force New-Item -Path $GeckoDriverPath -ItemType Directory -Force
} }

View File

@@ -8,28 +8,25 @@ Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
# Install the latest version of Git for Windows # Install the latest version of Git for Windows
$repoURL = "https://api.github.com/repos/git-for-windows/git/releases/latest" $repoURL = "https://api.github.com/repos/git-for-windows/git/releases/latest"
$gitReleases = Invoke-RestMethod $repoURL $gitReleases = Invoke-RestMethod $repoURL
[string]$downloadUrl = $gitReleases.assets.browser_download_url -match "Git-.+-64-bit.exe" $downloadUrl = $gitReleases.assets.browser_download_url -match "Git-.+-64-bit.exe" | Select-Object -First 1
$installerFile = Split-Path $downloadUrl -Leaf $installerFile = Split-Path $downloadUrl -Leaf
$packagePath = Start-DownloadWithRetry -Url $downloadUrl -Name $installerFile
#region Supply chain security - Git
$fileHash = (Get-FileHash -Path $packagePath -Algorithm SHA256).Hash
$externalHash = Get-HashFromGitHubReleaseBody -Url $RepoURL -FileName $installerFile $externalHash = Get-HashFromGitHubReleaseBody -Url $RepoURL -FileName $installerFile
Use-ChecksumComparison $fileHash $externalHash
#endregion
Install-Binary -FilePath $packagePath ` Install-Binary `
-ArgumentList ( -Url $downloadUrl `
"/VERYSILENT", ` -InstallArgs @(`
"/NORESTART", ` "/VERYSILENT", `
"/NOCANCEL", ` "/NORESTART", `
"/SP-", ` "/NOCANCEL", `
"/CLOSEAPPLICATIONS", ` "/SP-", `
"/RESTARTAPPLICATIONS", ` "/CLOSEAPPLICATIONS", `
"/o:PathOption=CmdTools", ` "/RESTARTAPPLICATIONS", `
"/o:BashTerminalOption=ConHost", ` "/o:PathOption=CmdTools", `
"/o:EnableSymlinks=Enabled", ` "/o:BashTerminalOption=ConHost", `
"/COMPONENTS=gitlfs") "/o:EnableSymlinks=Enabled", `
"/COMPONENTS=gitlfs") `
-ExpectedSHA256Sum $externalHash
Update-SessionEnvironment Update-SessionEnvironment
@@ -42,7 +39,7 @@ git config --system --add safe.directory "*"
Add-MachinePathItem "C:\Program Files\Git\bin" Add-MachinePathItem "C:\Program Files\Git\bin"
# Add well-known SSH host keys to ssh_known_hosts # Add well-known SSH host keys to ssh_known_hosts
ssh-keyscan -t rsa,ecdsa,ed25519 github.com >> "C:\Program Files\Git\etc\ssh\ssh_known_hosts" ssh-keyscan -t rsa, ecdsa, ed25519 github.com >> "C:\Program Files\Git\etc\ssh\ssh_known_hosts"
ssh-keyscan -t rsa ssh.dev.azure.com >> "C:\Program Files\Git\etc\ssh\ssh_known_hosts" ssh-keyscan -t rsa ssh.dev.azure.com >> "C:\Program Files\Git\etc\ssh\ssh_known_hosts"
Invoke-PesterTests -TestFile "Git" Invoke-PesterTests -TestFile "Git"

View File

@@ -7,19 +7,15 @@
Write-Host "Get the latest gh version..." Write-Host "Get the latest gh version..."
$repoUrl = "https://api.github.com/repos/cli/cli/releases/latest" $repoUrl = "https://api.github.com/repos/cli/cli/releases/latest"
$installerFile = "gh_windows_amd64.msi"
$assets = (Invoke-RestMethod -Uri $repoUrl).assets $assets = (Invoke-RestMethod -Uri $repoUrl).assets
$downloadUrl = ($assets.browser_download_url -match "windows_amd64.msi") | Select-Object -First 1 $downloadUrl = ($assets.browser_download_url -match "windows_amd64.msi") | Select-Object -First 1
$packagePath = Start-DownloadWithRetry -Url $downloadUrl -Name $installerFile
#region Supply chain security - GitHub CLI
$fileHash = (Get-FileHash -Path $packagePath -Algorithm SHA256).Hash
$hashUrl = ($assets.browser_download_url -match "checksums.txt") | Select-Object -First 1 $hashUrl = ($assets.browser_download_url -match "checksums.txt") | Select-Object -First 1
$externalHash = (Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*windows_amd64.msi*" }).Split(' ')[0] $externalHash = (Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*windows_amd64.msi*" }).Split(' ')[0]
Use-ChecksumComparison $fileHash $externalHash
#endregion
Install-Binary -FilePath $packagePath Install-Binary `
-Url $downloadUrl `
-ExpectedSHA256Sum $externalHash
Add-MachinePathItem "C:\Program Files (x86)\GitHub CLI" Add-MachinePathItem "C:\Program Files (x86)\GitHub CLI"

View File

@@ -4,10 +4,9 @@
################################################################################ ################################################################################
# https://cloud.google.com/sdk/docs/downloads-interactive # https://cloud.google.com/sdk/docs/downloads-interactive
$googleCloudCLIInstaller = "https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe" Install-Binary `
$argumentList = @("/S", "/allusers", "/noreporting") -Url 'https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe' `
$googleCloudCLISignatureThumbprint = "2673EA6CC23BEFFDA49AC715B121544098A1284C" -InstallArgs @("/S", "/allusers", "/noreporting") `
-ExpectedSignature '2673EA6CC23BEFFDA49AC715B121544098A1284C'
Install-Binary -Url $googleCloudCLIInstaller -Name "GoogleCloudSDKInstaller.exe" -ArgumentList $argumentList -ExpectedSignature $googleCloudCLISignatureThumbprint
Invoke-PesterTests -TestFile "Tools" -TestName "GoogleCloudCLI" Invoke-PesterTests -TestFile "Tools" -TestName "GoogleCloudCLI"

View File

@@ -114,13 +114,13 @@ foreach ($jdkVersionToInstall in $jdkVersionsToInstall) {
# Install Java tools # Install Java tools
# Force chocolatey to ignore dependencies on Ant and Maven or else they will download the Oracle JDK # Force chocolatey to ignore dependencies on Ant and Maven or else they will download the Oracle JDK
Choco-Install -PackageName ant -ArgumentList "-i" Install-ChocoPackage ant -ArgumentList "--ignore-dependencies"
# Maven 3.9.x has multiple compatibilities problems # Maven 3.9.x has multiple compatibilities problems
$toolsetMavenVersion = (Get-ToolsetContent).maven.version $toolsetMavenVersion = (Get-ToolsetContent).maven.version
$versionToInstall = Get-LatestChocoPackageVersion -TargetVersion $toolsetMavenVersion -PackageName "maven" $versionToInstall = Resolve-ChocoPackageVersion -PackageName "maven" -TargetVersion $toolsetMavenVersion
Choco-Install -PackageName maven -ArgumentList "--version=$versionToInstall" Install-ChocoPackage maven -ArgumentList "--version=$versionToInstall"
Choco-Install -PackageName gradle Install-ChocoPackage gradle
# Add maven env variables to Machine # Add maven env variables to Machine
[string]$m2 = (Get-MachinePath).Split(";") -match "maven" [string]$m2 = (Get-MachinePath).Split(";") -match "maven"

View File

@@ -23,12 +23,12 @@ Use-ChecksumComparison $fileHash $externalHash
Add-MachinePathItem $destFilePath Add-MachinePathItem $destFilePath
Write-Host "Install Kubectl" Write-Host "Install Kubectl"
Choco-Install -PackageName kubernetes-cli Install-ChocoPackage kubernetes-cli
Write-Host "Install Helm" Write-Host "Install Helm"
Choco-Install -PackageName kubernetes-helm Install-ChocoPackage kubernetes-helm
Write-Host "Install Minikube" Write-Host "Install Minikube"
Choco-Install -PackageName minikube Install-ChocoPackage minikube
Invoke-PesterTests -TestFile "Tools" -TestName "KubernetesTools" Invoke-PesterTests -TestFile "Tools" -TestName "KubernetesTools"

View File

@@ -4,7 +4,7 @@
################################################################################ ################################################################################
$llvmVersion = (Get-ToolsetContent).llvm.version $llvmVersion = (Get-ToolsetContent).llvm.version
$latestChocoVersion = Get-LatestChocoPackageVersion -TargetVersion $llvmVersion -PackageName "llvm" $latestChocoVersion = Resolve-ChocoPackageVersion -PackageName "llvm" -TargetVersion $llvmVersion
Choco-Install -PackageName llvm -ArgumentList '--version', $latestChocoVersion Install-ChocoPackage llvm -ArgumentList '--version', $latestChocoVersion
Invoke-PesterTests -TestFile "LLVM" Invoke-PesterTests -TestFile "LLVM"

View File

@@ -3,10 +3,10 @@
## Desc: Install Mercurial ## Desc: Install Mercurial
################################################################################ ################################################################################
Choco-Install -PackageName hg -ArgumentList "--version", "5.0.0" Install-ChocoPackage hg -ArgumentList "--version", "5.0.0"
$hgPath = "${env:ProgramFiles}\Mercurial\" $hgPath = "${env:ProgramFiles}\Mercurial\"
Add-MachinePathItem $hgPath Add-MachinePathItem $hgPath
$env:Path = Get-MachinePath $env:Path = Get-MachinePath
Invoke-PesterTests -TestFile "Tools" -TestName "Mercurial" Invoke-PesterTests -TestFile "Tools" -TestName "Mercurial"

View File

@@ -5,28 +5,28 @@
################################################################################ ################################################################################
$CondaDestination = "C:\Miniconda" $CondaDestination = "C:\Miniconda"
# Install the latest Miniconda
$InstallerName = "Miniconda3-latest-Windows-x86_64.exe" $InstallerName = "Miniconda3-latest-Windows-x86_64.exe"
$InstallerUrl = "https://repo.anaconda.com/miniconda/${InstallerName}"
$ArgumentList = ("/S", "/AddToPath=0", "/RegisterPython=0", "/D=$CondaDestination")
Install-Binary -Url $InstallerUrl -Name $InstallerName -ArgumentList $ArgumentList
[System.Environment]::SetEnvironmentVariable("CONDA", $CondaDestination, "Machine")
#region Supply chain security #region Supply chain security
$localFileHash = (Get-FileHash -Path (Join-Path ${env:TEMP} $installerName) -Algorithm SHA256).Hash
$distributorFileHash = $null $distributorFileHash = $null
$checksums = (Invoke-RestMethod -Uri 'https://repo.anaconda.com/miniconda/' | ConvertFrom-HTML).SelectNodes('//html/body/table/tr') $checksums = (Invoke-RestMethod -Uri 'https://repo.anaconda.com/miniconda/' | ConvertFrom-HTML).SelectNodes('//html/body/table/tr')
ForEach($node in $checksums) { foreach ($node in $checksums) {
if ($node.ChildNodes[1].InnerText -eq $InstallerName) { if ($node.ChildNodes[1].InnerText -eq $InstallerName) {
$distributorFileHash = $node.ChildNodes[7].InnerText $distributorFileHash = $node.ChildNodes[7].InnerText
} }
} }
Use-ChecksumComparison -LocalFileHash $localFileHash -DistributorFileHash $distributorFileHash if ($null -eq $distributorFileHash) {
throw "Unable to find checksum for $InstallerName in https://repo.anaconda.com/miniconda/"
}
#endregion #endregion
Install-Binary `
-Url "https://repo.anaconda.com/miniconda/${InstallerName}" `
-InstallArgs @("/S", "/AddToPath=0", "/RegisterPython=0", "/D=$CondaDestination") `
-ExpectedSHA256Sum $distributorFileHash
[System.Environment]::SetEnvironmentVariable("CONDA", $CondaDestination, "Machine")
Invoke-PesterTests -TestFile "Miniconda" Invoke-PesterTests -TestFile "Miniconda"

View File

@@ -20,12 +20,10 @@ foreach ($release in $TargetReleases) {
$LatestVersion = $MinorVersions[0] $LatestVersion = $MinorVersions[0]
$installDir = "c:\PROGRA~1\MongoDB" Install-Binary `
$binaryName = "mongodb-windows-x86_64-$LatestVersion-signed.msi" -Url "https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-$LatestVersion-signed.msi" `
$downloadURL = "https://fastdl.mongodb.org/windows/$BinaryName" -ExtraInstallArgs @('TARGETDIR=C:\PROGRA~1\MongoDB ADDLOCAL=ALL') `
$installArg = "INSTALLLOCATION=$installDir ADDLOCAL=all" -ExpectedSignature (Get-ToolsetContent).mongodb.signature
Install-Binary -Url $downloadURL -Name $binaryName -ArgumentList ("/q","/i","${env:Temp}\$binaryName", $installArg) -ExpectedSignature (Get-ToolsetContent).mongodb.signature
# Add mongodb to the PATH # Add mongodb to the PATH
$mongodbService = "mongodb" $mongodbService = "mongodb"

View File

@@ -4,26 +4,26 @@
################################################################################ ################################################################################
# Installing visual c++ redistibutable package. # Installing visual c++ redistibutable package.
$InstallerName = "vcredist_x64.exe" Install-Binary `
$InstallerURI = "https://download.microsoft.com/download/0/5/6/056dcda9-d667-4e27-8001-8a0c6971d6b1/${InstallerName}" -Url 'https://download.microsoft.com/download/0/5/6/056dcda9-d667-4e27-8001-8a0c6971d6b1/vcredist_x64.exe' `
$ArgumentList = ("/install", "/quiet", "/norestart") -InstallArgs @("/install", "/quiet", "/norestart") `
$InstallerSignatureThumbrint = "3BDA323E552DB1FDE5F4FBEE75D6D5B2B187EEDC" -ExpectedSignature '3BDA323E552DB1FDE5F4FBEE75D6D5B2B187EEDC'
Install-Binary -Url $InstallerURI -Name $InstallerName -ArgumentList $ArgumentList -ExpectedSignature $InstallerSignatureThumbrint
# Downloading mysql # Downloading mysql
[version]$MysqlVersion = (Get-ToolsetContent).mysql.version [version]$MysqlVersion = (Get-ToolsetContent).mysql.version
$MysqlVersionMajorMinor = $MysqlVersion.ToString(2) $MysqlVersionMajorMinor = $MysqlVersion.ToString(2)
if ($MysqlVersion.Build -lt 0) { if ($MysqlVersion.Build -lt 0) {
$MysqlVersion = (Invoke-RestMethod -Uri "https://dev.mysql.com/downloads/mysql/${MysqlVersionMajorMinor}.html" -Headers @{ 'User-Agent'='curl/8.4.0' } | $MysqlVersion = (Invoke-RestMethod -Uri "https://dev.mysql.com/downloads/mysql/${MysqlVersionMajorMinor}.html" -Headers @{ 'User-Agent' = 'curl/8.4.0' } |
Select-String -Pattern "${MysqlVersionMajorMinor}\.\d+").Matches.Value Select-String -Pattern "${MysqlVersionMajorMinor}\.\d+").Matches.Value
} }
$MysqlVersionFull = $MysqlVersion.ToString() $MysqlVersionFull = $MysqlVersion.ToString()
$MysqlVersionUrl = "https://cdn.mysql.com/Downloads/MySQL-${MysqlVersionMajorMinor}/mysql-${MysqlVersionFull}-winx64.msi" $MysqlVersionUrl = "https://cdn.mysql.com/Downloads/MySQL-${MysqlVersionMajorMinor}/mysql-${MysqlVersionFull}-winx64.msi"
Install-Binary -Url $MysqlVersionUrl -Name "mysql-${MysqlVersionFull}-winx64.msi" -ExpectedSignature (Get-ToolsetContent).mysql.signature Install-Binary `
-Url $MysqlVersionUrl `
-ExpectedSignature (Get-ToolsetContent).mysql.signature
# Adding mysql in system environment path # Adding mysql in system environment path
$MysqlPath = $(Get-ChildItem -Path "C:\PROGRA~1\MySQL" -Directory)[0].FullName $MysqlPath = $(Get-ChildItem -Path "C:\PROGRA~1\MySQL" -Directory)[0].FullName

View File

@@ -4,11 +4,9 @@
################################################################################ ################################################################################
# .NET 4.8 Dev pack # .NET 4.8 Dev pack
$InstallerName = "ndp48-devpack-enu.exe" Install-Binary `
$InstallerUrl = "https://download.visualstudio.microsoft.com/download/pr/014120d7-d689-4305-befd-3cb711108212/0307177e14752e359fde5423ab583e43/${InstallerName}" -Url 'https://download.visualstudio.microsoft.com/download/pr/014120d7-d689-4305-befd-3cb711108212/0307177e14752e359fde5423ab583e43/ndp48-devpack-enu.exe' `
$InstallerSignatureThumbprint = "C82273A065EC470FB1EBDE846A91E6FFB29E9C12" -InstallArgs @("Setup", "/passive", "/norestart") `
$ArgumentList = ("Setup", "/passive", "/norestart") -ExpectedSignature 'C82273A065EC470FB1EBDE846A91E6FFB29E9C12'
Install-Binary -Url $InstallerUrl -Name $InstallerName -ArgumentList $ArgumentList -ExpectedSignature $InstallerSignatureThumbprint
Invoke-PesterTests -TestFile "Tools" -TestName "NET48" Invoke-PesterTests -TestFile "Tools" -TestName "NET48"

View File

@@ -4,9 +4,7 @@
################################################################################ ################################################################################
# .NET 4.8 Dev pack # .NET 4.8 Dev pack
$InstallerName = "ndp48-x86-x64-allos-enu.exe" Install-Binary `
$InstallerUrl = "https://download.visualstudio.microsoft.com/download/pr/2d6bb6b2-226a-4baa-bdec-798822606ff1/8494001c276a4b96804cde7829c04d7f/${InstallerName}" -Url 'https://download.visualstudio.microsoft.com/download/pr/2d6bb6b2-226a-4baa-bdec-798822606ff1/8494001c276a4b96804cde7829c04d7f/ndp48-x86-x64-allos-enu.exe' `
$InstallerSignatureThumbprint = "ABDCA79AF9DD48A0EA702AD45260B3C03093FB4B" -InstallArgs @("Setup", "/passive", "/norestart") `
$ArgumentList = ("Setup", "/passive", "/norestart") -ExpectedSignature 'ABDCA79AF9DD48A0EA702AD45260B3C03093FB4B'
Install-Binary -Url $InstallerUrl -Name $InstallerName -ArgumentList $ArgumentList -ExpectedSignature $InstallerSignatureThumbprint

View File

@@ -6,7 +6,7 @@
$NsisVersion = (Get-ToolsetContent).nsis.version $NsisVersion = (Get-ToolsetContent).nsis.version
Choco-Install -PackageName nsis -ArgumentList "--version", "$NsisVersion" Install-ChocoPackage nsis -ArgumentList "--version", "$NsisVersion"
$NsisPath = "${env:ProgramFiles(x86)}\NSIS\" $NsisPath = "${env:ProgramFiles(x86)}\NSIS\"
Add-MachinePathItem $NsisPath Add-MachinePathItem $NsisPath

View File

@@ -8,7 +8,7 @@ Stop-Service -Name w3svc | Out-Null
# Install latest nginx in chocolatey # Install latest nginx in chocolatey
$installDir = "C:\tools" $installDir = "C:\tools"
Choco-Install -PackageName nginx -ArgumentList "--force", "--params", "/installLocation:$installDir /port:80" Install-ChocoPackage nginx -ArgumentList "--force", "--params", "/installLocation:$installDir /port:80"
# Stop and disable Nginx service # Stop and disable Nginx service
Stop-Service -Name nginx Stop-Service -Name nginx

View File

@@ -11,9 +11,9 @@ New-Item -Path $PrefixPath -Force -ItemType Directory
New-Item -Path $CachePath -Force -ItemType Directory New-Item -Path $CachePath -Force -ItemType Directory
$defaultVersion = (Get-ToolsetContent).node.default $defaultVersion = (Get-ToolsetContent).node.default
$versionToInstall = Get-LatestChocoPackageVersion -TargetVersion $defaultVersion -PackageName "nodejs" $versionToInstall = Resolve-ChocoPackageVersion -PackageName "nodejs" -TargetVersion $defaultVersion
Choco-Install -PackageName nodejs -ArgumentList "--version=$versionToInstall" Install-ChocoPackage nodejs -ArgumentList "--version=$versionToInstall"
Add-MachinePathItem $PrefixPath Add-MachinePathItem $PrefixPath
$env:Path = Get-MachinePath $env:Path = Get-MachinePath

View File

@@ -7,7 +7,7 @@
$arch = 'INTEL' $arch = 'INTEL'
$bits = '64' $bits = '64'
$light = $false $light = $false
$installer = "exe" $installerType = "exe"
$version = (Get-ToolsetContent).openssl.version $version = (Get-ToolsetContent).openssl.version
$installDir = "$Env:ProgramFiles\OpenSSL" $installDir = "$Env:ProgramFiles\OpenSSL"
@@ -15,35 +15,27 @@ $installDir = "$Env:ProgramFiles\OpenSSL"
$jsonUrl = 'https://raw.githubusercontent.com/slproweb/opensslhashes/master/win32_openssl_hashes.json' $jsonUrl = 'https://raw.githubusercontent.com/slproweb/opensslhashes/master/win32_openssl_hashes.json'
$installersAvailable = (Invoke-RestMethod $jsonUrl).files $installersAvailable = (Invoke-RestMethod $jsonUrl).files
$installerNames = $installersAvailable | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name
$distributor_file_hash = $null
$installerUrl = $null $installerUrl = $null
$installerName = $null $installerHash = $null
$installersAvailable | Get-Member -MemberType NoteProperty | ForEach-Object { foreach ($key in $installerNames) {
$key = $_.Name $installer = $installersAvailable.$key
if(($installersAvailable.$key.light -eq $light) -and ($installersAvailable.$key.arch -eq $arch) -and ($installersAvailable.$key.bits -eq $bits) -and ($installersAvailable.$key.installer -eq $installer) -and ($installersAvailable.$key.basever -eq $version)) { if (($installer.light -eq $light) -and ($installer.arch -eq $arch) -and ($installer.bits -eq $bits) -and ($installer.installer -eq $installerType) -and ($installer.basever -eq $version)) {
$installerUrl = $installersAvailable.$key.url $installerUrl = $installer.url
$installerName = $key $installerHash = $installer.sha512
$distributor_file_hash = $installersAvailable.$key.sha512 }
}
} }
# Invoke installation if ($null -eq $installerUrl) {
throw "Installer not found for version $version"
$installerArgs = '/silent', '/sp-', '/suppressmsgboxes', "/DIR=`"$installDir`""
Install-Binary -Url "$installerUrl" -Name "$installerName" -ArgumentList $installerArgs
#region Supply chain security
Write-Verbose "Performing checksum verification"
$local_file_hash = (Get-FileHash -Path (Join-Path ${env:TEMP} $installerName) -Algorithm SHA512).Hash
if ($local_file_hash -ne $distributor_file_hash) {
Write-Host "hash must be equal to: ${distributor_file_hash}"
Write-Host "actual hash is: ${local_file_hash}"
throw 'Checksum verification failed, please rerun install'
} }
#endregion
Install-Binary `
-Url $installerUrl `
-InstallArgs @('/silent', '/sp-', '/suppressmsgboxes', "/DIR=`"$installDir`"") `
-ExpectedSHA512Sum $installerHash
# Update PATH # Update PATH
Add-MachinePathItem "$installDir\bin" Add-MachinePathItem "$installDir\bin"

View File

@@ -6,11 +6,11 @@
# Install latest PHP in chocolatey # Install latest PHP in chocolatey
$installDir = "c:\tools\php" $installDir = "c:\tools\php"
$phpMajorMinor = (Get-ToolsetContent).php.version $phpMajorMinor = (Get-ToolsetContent).php.version
$phpVersionToInstall = Get-LatestChocoPackageVersion -TargetVersion $phpMajorMinor -PackageName "php" $phpVersionToInstall = Resolve-ChocoPackageVersion -PackageName "php" -TargetVersion $phpMajorMinor
Choco-Install -PackageName php -ArgumentList "--params", "/InstallDir:$installDir", "--version=$phpVersionToInstall" Install-ChocoPackage php -ArgumentList "--params", "/InstallDir:$installDir", "--version=$phpVersionToInstall"
# Install latest Composer in chocolatey # Install latest Composer in chocolatey
Choco-Install -PackageName composer -ArgumentList "--ia", "/DEV=$installDir /PHP=$installDir" Install-ChocoPackage composer -ArgumentList "--install-args", "/DEV=$installDir /PHP=$installDir"
# update path to extensions and enable curl and mbstring extensions, and enable php openssl extensions. # update path to extensions and enable curl and mbstring extensions, and enable php openssl extensions.
((Get-Content -path $installDir\php.ini -Raw) -replace ';extension=curl','extension=curl' -replace ';extension=mbstring','extension=mbstring' -replace ';extension_dir = "ext"','extension_dir = "ext"' -replace ';extension=openssl','extension=openssl') | Set-Content -Path $installDir\php.ini ((Get-Content -path $installDir\php.ini -Raw) -replace ';extension=curl','extension=curl' -replace ';extension=mbstring','extension=mbstring' -replace ';extension_dir = "ext"','extension_dir = "ext"' -replace ';extension=openssl','extension=openssl') | Set-Content -Path $installDir\php.ini

View File

@@ -44,11 +44,14 @@ do {
$increment-- $increment--
} }
} while (!$response) } while (!$response)
# Return the previous value of ErrorAction and invoke Install-Binary function # Return the previous value of ErrorAction and invoke Install-Binary function
$ErrorActionPreference = $ErrorActionOldValue $ErrorActionPreference = $ErrorActionOldValue
$InstallerName = $InstallerUrl.Split('/')[-1] $InstallerArgs = @("--install_runtimes 0", "--superpassword root", "--enable_acledit 1", "--unattendedmodeui none", "--mode unattended")
$ArgumentList = ("--install_runtimes 0", "--superpassword root", "--enable_acledit 1", "--unattendedmodeui none", "--mode unattended") Install-Binary `
Install-Binary -Url $InstallerUrl -Name $InstallerName -ArgumentList $ArgumentList -ExpectedSignature (Get-ToolsetContent).postgresql.signature -Url $InstallerUrl `
-InstallArgs $InstallerArgs `
-ExpectedSignature (Get-ToolsetContent).postgresql.signature
# Get Path to pg_ctl.exe # Get Path to pg_ctl.exe
$pgPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").PathName $pgPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").PathName

View File

@@ -6,20 +6,6 @@
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
#region functions
Function Get-PowerShellCoreHash
{
Param (
[Parameter(Mandatory = $True)]
[string] $Release
)
$hashURL = "https://github.com/PowerShell/PowerShell/releases/download/v${Release}/hashes.sha256"
(Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*PowerShell-${Release}-win-x64.msi*" }).Split(' ')[0]
}
#endregion
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName()) $tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
$null = New-Item -ItemType Directory -Path $tempDir -Force -ErrorAction SilentlyContinue $null = New-Item -ItemType Directory -Path $tempDir -Force -ErrorAction SilentlyContinue
try { try {
@@ -28,33 +14,12 @@ try {
$metadata = Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json $metadata = Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json
$release = $metadata.LTSReleaseTag[0] -replace '^v' $release = $metadata.LTSReleaseTag[0] -replace '^v'
$packageName = "PowerShell-${release}-win-x64.msi" $downloadUrl = "https://github.com/PowerShell/PowerShell/releases/download/v${release}/PowerShell-${release}-win-x64.msi"
$downloadURL = "https://github.com/PowerShell/PowerShell/releases/download/v${release}/${packageName}" $hashUrl = "https://github.com/PowerShell/PowerShell/releases/download/v${release}/hashes.sha256"
Write-Verbose "About to download package from '$downloadURL'" -Verbose $expectedSHA256Sum = (Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*PowerShell-${Release}-win-x64.msi*" }).Split(' ')[0]
$packagePath = Join-Path -Path $tempDir -ChildPath $packageName Install-Binary -Url $downloadUrl -ExpectedSHA256Sum $expectedSHA256Sum
Invoke-WebRequest -Uri $downloadURL -OutFile $packagePath
#region Supply chain security
Write-Verbose "Performing checksum verification"
$distributor_file_hash = Get-PowerShellCoreHash -Release $release
$local_file_hash = (Get-FileHash -Path $packagePath -Algorithm SHA256).Hash
if ($local_file_hash -ne $distributor_file_hash) {
Write-Host "hash must be equal to: ${distributor_file_hash}"
Write-Host "actual hash is: ${local_file_hash}"
throw 'Checksum verification failed, please rerun install'
}
#endregion
Write-Verbose "Performing quiet install"
$ArgumentList=@("/i", $packagePath, "/quiet")
$process = Start-Process msiexec -ArgumentList $ArgumentList -Wait -PassThru
if ($process.exitcode -ne 0) {
throw "Quiet install failed, please rerun install without -Quiet switch or ensure you have administrator rights"
}
} finally { } finally {
# Restore original value # Restore original value
[Net.ServicePointManager]::SecurityProtocol = $originalValue [Net.ServicePointManager]::SecurityProtocol = $originalValue

View File

@@ -3,9 +3,9 @@
## Desc: Install R for Windows ## Desc: Install R for Windows
################################################################################ ################################################################################
Choco-Install R.Project Install-ChocoPackage R.Project
Choco-Install rtools Install-ChocoPackage rtools
$rscriptPath = Resolve-Path "C:\Program Files\R\*\bin\x64" $rscriptPath = Resolve-Path "C:\Program Files\R\*\bin\x64"
Add-MachinePathItem $rscriptPath Add-MachinePathItem $rscriptPath
Invoke-PesterTests -TestFile "Tools" -TestName "R" Invoke-PesterTests -TestFile "Tools" -TestName "R"

View File

@@ -3,7 +3,7 @@
## Desc: Install OLE DB Driver for SQL Server ## Desc: Install OLE DB Driver for SQL Server
################################################################################ ################################################################################
$binaryDownloadPath = Start-DownloadWithRetry "https://go.microsoft.com/fwlink/?linkid=2242656" "msoledbsql.msi" Install-Binary -Type MSI `
$binarySignatureThumbprint = "6E78B3DCE2998F6C2457C3E54DA90A01034916AE" -Url "https://go.microsoft.com/fwlink/?linkid=2242656" `
$ArgumentList = ("/i", "$binaryDownloadPath", "ADDLOCAL=ALL", "IACCEPTMSOLEDBSQLLICENSETERMS=YES", "/qn") -ExtraInstallArgs @("ADDLOCAL=ALL", "IACCEPTMSOLEDBSQLLICENSETERMS=YES") `
Install-Binary -FilePath $binaryDownloadPath -ArgumentList $ArgumentList -ExpectedSignature $binarySignatureThumbprint -ExpectedSignature '6E78B3DCE2998F6C2457C3E54DA90A01034916AE'

View File

@@ -3,18 +3,18 @@
## Desc: Install SQL PowerShell tool ## Desc: Install SQL PowerShell tool
################################################################################ ################################################################################
$BaseUrl = "https://download.microsoft.com/download/B/1/7/B1783FE9-717B-4F78-A39A-A2E27E3D679D/ENU/x64" $baseUrl = "https://download.microsoft.com/download/B/1/7/B1783FE9-717B-4F78-A39A-A2E27E3D679D/ENU/x64"
$SignatureThumbrint = "9ACA9419E53D3C9E56396DD2335FF683A8B0B8F3" $signatureThumbrint = "9ACA9419E53D3C9E56396DD2335FF683A8B0B8F3"
# install required MSIs # install required MSIs
$SQLSysClrTypesName = "SQLSysClrTypes.msi" Install-Binary `
$SQLSysClrTypesUrl = "${BaseUrl}/${SQLSysClrTypesName}" -Url "${baseUrl}/SQLSysClrTypes.msi" `
Install-Binary -Url $SQLSysClrTypesUrl -Name $SQLSysClrTypesName -ExpectedSignature $SignatureThumbrint -ExpectedSignature $signatureThumbrint
$SharedManagementObjectsName = "SharedManagementObjects.msi" Install-Binary `
$SharedManagementObjectsUrl = "${BaseUrl}/${SharedManagementObjectsName}" -Url "${baseUrl}/SharedManagementObjects.msi" `
Install-Binary -Url $SharedManagementObjectsUrl -Name $SharedManagementObjectsName -ExpectedSignature $SignatureThumbrint -ExpectedSignature $signatureThumbrint
$PowerShellToolsName = "PowerShellTools.msi" Install-Binary `
$PowerShellToolsUrl = "${BaseUrl}/${PowerShellToolsName}" -Url "${baseUrl}/PowerShellTools.msi" `
Install-Binary -Url $PowerShellToolsUrl -Name $PowerShellToolsName -ExpectedSignature $SignatureThumbrint -ExpectedSignature $signatureThumbrint

View File

@@ -5,7 +5,7 @@
# Install the latest version of sbt. # Install the latest version of sbt.
# See https://chocolatey.org/packages/sbt # See https://chocolatey.org/packages/sbt
Choco-Install -PackageName sbt Install-ChocoPackage sbt
$env:SBT_HOME="${env:ProgramFiles(x86)}\sbt" $env:SBT_HOME="${env:ProgramFiles(x86)}\sbt"

View File

@@ -8,18 +8,19 @@
New-Item -Path 'C:\Windows\Installer' -ItemType Directory -Force New-Item -Path 'C:\Windows\Installer' -ItemType Directory -Force
# Get Service Fabric components versions # Get Service Fabric components versions
$serviceFabricRuntimeVersion = (Get-ToolsetContent).serviceFabric.runtime.version $runtimeVersion = (Get-ToolsetContent).serviceFabric.runtime.version
$serviceFabricSDKVersion = (Get-ToolsetContent).serviceFabric.sdk.version $sdkVersion = (Get-ToolsetContent).serviceFabric.sdk.version
$urlBase = "https://download.microsoft.com/download/b/8/a/b8a2fb98-0ec1-41e5-be98-9d8b5abf7856"
# Install Service Fabric Runtime for Windows # Install Service Fabric Runtime for Windows
$InstallerName = "MicrosoftServiceFabric.${serviceFabricRuntimeVersion}.exe" Install-Binary `
$InstallerUrl = "https://download.microsoft.com/download/b/8/a/b8a2fb98-0ec1-41e5-be98-9d8b5abf7856/${InstallerName}" -Url "${urlBase}/MicrosoftServiceFabric.${runtimeVersion}.exe" `
$ArgumentList = ("/accepteula ","/quiet","/force") -InstallArgs @("/accepteula ", "/quiet", "/force") `
Install-Binary -Url $InstallerUrl -Name $InstallerName -ArgumentList $ArgumentList -ExpectedSignature (Get-ToolsetContent).serviceFabric.runtime.signature -ExpectedSignature (Get-ToolsetContent).serviceFabric.runtime.signature
# Install Service Fabric SDK # Install Service Fabric SDK
$InstallerName = "MicrosoftServiceFabricSDK.${serviceFabricSDKVersion}.msi" Install-Binary `
$InstallerUrl = "https://download.microsoft.com/download/b/8/a/b8a2fb98-0ec1-41e5-be98-9d8b5abf7856/${InstallerName}" -Url "${urlBase}/MicrosoftServiceFabricSDK.${sdkVersion}.msi" `
Install-Binary -Url $InstallerUrl -Name $InstallerName -ExpectedSignature (Get-ToolsetContent).serviceFabric.sdk.signature -ExpectedSignature (Get-ToolsetContent).serviceFabric.sdk.signature
Invoke-PesterTests -TestFile "Tools" -TestName "ServiceFabricSDK" Invoke-PesterTests -TestFile "Tools" -TestName "ServiceFabricSDK"

View File

@@ -3,14 +3,18 @@
## Desc: Install Visual C++ Redistributable ## Desc: Install Visual C++ Redistributable
################################################################################ ################################################################################
$vc2010x86Name = "vcredist_x86.exe" $baseUrl = "https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC"
$vc2010x86URI = "https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/${vc2010x86Name}"
$vc2010x64Name = "vcredist_x64.exe"
$vc2010x64URI = "https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/${Vc2010x64Name}"
$argumentList = ("/install", "/quiet", "/norestart") $argumentList = ("/install", "/quiet", "/norestart")
$vcSignatureThumbprint = "ABDCA79AF9DD48A0EA702AD45260B3C03093FB4B" $signatureThumbrint = "ABDCA79AF9DD48A0EA702AD45260B3C03093FB4B"
Install-Binary -Url $vc2010x86URI -Name $vc2010x86Name -ArgumentList $argumentList -ExpectedSignature $vcSignatureThumbprint Install-Binary `
Install-Binary -Url $vc2010x64URI -Name $vc2010x64Name -ArgumentList $argumentList -ExpectedSignature $vcSignatureThumbprint -Url "${baseUrl}/vcredist_x86.exe" `
-InstallArgs $argumentList `
-ExpectedSignature $signatureThumbrint
Install-Binary `
-Url "${baseUrl}/vcredist_x64.exe" `
-InstallArgs $argumentList `
-ExpectedSignature $signatureThumbrint
Invoke-PesterTests -TestFile "Tools" -TestName "VCRedist" Invoke-PesterTests -TestFile "Tools" -TestName "VCRedist"

View File

@@ -16,8 +16,9 @@ $vsixPackagesList | ForEach-Object {
if ($vsixPackage.FileName.EndsWith(".vsix")) { if ($vsixPackage.FileName.EndsWith(".vsix")) {
Install-VsixExtension -Url $vsixPackage.DownloadUri -Name $vsixPackage.FileName Install-VsixExtension -Url $vsixPackage.DownloadUri -Name $vsixPackage.FileName
} else { } else {
$argumentList = ('/install', '/quiet', '/norestart') Install-Binary `
Install-Binary -Url $vsixPackage.DownloadUri -Name $vsixPackage.FileName -ArgumentList $argumentList -Url $vsixPackage.DownloadUri `
-InstallArgs @('/install', '/quiet', '/norestart')
} }
} }

View File

@@ -30,29 +30,25 @@ $newContent = '{"Extensions":[{"Key":"1e906ff5-9da8-4091-a299-5c253c55fdc9","Val
Set-Content -Path "$vsInstallRoot\Common7\IDE\Extensions\MachineState.json" -Value $newContent Set-Content -Path "$vsInstallRoot\Common7\IDE\Extensions\MachineState.json" -Value $newContent
if (Test-IsWin19) { if (Test-IsWin19) {
# Install Windows 10 SDK version 10.0.14393.795 # Install Windows 10 SDK version 10.0.14393.795
$sdkSignatureThumbprint = "C91545B333C52C4465DE8B90A3FAF4E1D9C58DFA" Install-Binary -Type EXE `
$sdkUrl = "https://go.microsoft.com/fwlink/p/?LinkId=838916" -Url 'https://go.microsoft.com/fwlink/p/?LinkId=838916' `
$sdkFileName = "sdksetup14393.exe" -InstallArgs @("/q", "/norestart", "/ceip off", "/features OptionId.WindowsSoftwareDevelopmentKit") `
$argumentList = ("/q", "/norestart", "/ceip off", "/features OptionId.WindowsSoftwareDevelopmentKit") -ExpectedSignature 'C91545B333C52C4465DE8B90A3FAF4E1D9C58DFA'
Install-Binary -Url $sdkUrl -Name $sdkFileName -ArgumentList $argumentList -ExpectedSignature $sdkSignatureThumbprint
# Install Windows 11 SDK version 10.0.22621.0 # Install Windows 11 SDK version 10.0.22621.0
$sdkSignatureThumbprint = "E4C5C5FCDB68B930EE4E19BC25D431EF6D864C51" Install-Binary -Type EXE `
$sdkUrl = "https://go.microsoft.com/fwlink/p/?linkid=2196241" -Url 'https://go.microsoft.com/fwlink/p/?linkid=2196241' `
$sdkFileName = "sdksetup22621.exe" -InstallArgs @("/q", "/norestart", "/ceip off", "/features OptionId.UWPManaged OptionId.UWPCPP OptionId.UWPLocalized OptionId.DesktopCPPx86 OptionId.DesktopCPPx64 OptionId.DesktopCPParm64") `
$argumentList = ("/q", "/norestart", "/ceip off", "/features OptionId.UWPManaged OptionId.UWPCPP OptionId.UWPLocalized OptionId.DesktopCPPx86 OptionId.DesktopCPPx64 OptionId.DesktopCPParm64") -ExpectedSignature 'E4C5C5FCDB68B930EE4E19BC25D431EF6D864C51'
Install-Binary -Url $sdkUrl -Name $sdkFileName -ArgumentList $argumentList -ExpectedSignature $sdkSignatureThumbprint
} }
if (Test-IsWin22) { if (Test-IsWin22) {
# Install Windows 10 SDK version 10.0.17763 # Install Windows 10 SDK version 10.0.17763
$sdkSignatureThumbprint = "7535269B94C1FEA4A5EF6D808E371DA242F27936" Install-Binary -Type EXE `
$sdkUrl = "https://go.microsoft.com/fwlink/p/?LinkID=2033908" -Url 'https://go.microsoft.com/fwlink/p/?LinkID=2033908' `
$sdkFileName = "sdksetup17763.exe" -InstallArgs @("/q", "/norestart", "/ceip off", "/features OptionId.UWPManaged OptionId.UWPCPP OptionId.UWPLocalized OptionId.DesktopCPPx86 OptionId.DesktopCPPx64 OptionId.DesktopCPParm64") `
$argumentList = ("/q", "/norestart", "/ceip off", "/features OptionId.UWPManaged OptionId.UWPCPP OptionId.UWPLocalized OptionId.DesktopCPPx86 OptionId.DesktopCPPx64 OptionId.DesktopCPParm64") -ExpectedSignature '7535269B94C1FEA4A5EF6D808E371DA242F27936'
Install-Binary -Url $sdkUrl -Name $sdkFileName -ArgumentList $argumentList -ExpectedSignature $sdkSignatureThumbprint
} }
Invoke-PesterTests -TestFile "VisualStudio" Invoke-PesterTests -TestFile "VisualStudio"

View File

@@ -4,33 +4,33 @@
################################################################################ ################################################################################
# Requires Windows SDK with the same version number as the WDK # Requires Windows SDK with the same version number as the WDK
if (Test-IsWin22) { if (Test-IsWin19) {
# SDK available through Visual Studio # Install all features without showing the GUI using winsdksetup.exe
$wdkUrl = "https://go.microsoft.com/fwlink/?linkid=2249371" Install-Binary -Type EXE `
$FilePath = "C:\Program Files (x86)\Windows Kits\10\Vsix\VS2022\*\WDK.vsix" -Url 'https://go.microsoft.com/fwlink/?linkid=2173743' `
$wdkSignatureThumbprint = "7C94971221A799907BB45665663BBFD587BAC9F8" -InstallArgs @("/features", "+", "/quiet") `
} elseif (Test-IsWin19) { -ExpectedSignature '44796EB5BD439B4BFB078E1DC2F8345AE313CBB1'
$winSdkUrl = "https://go.microsoft.com/fwlink/?linkid=2173743"
$wdkUrl = "https://go.microsoft.com/fwlink/?linkid=2166289" $wdkUrl = "https://go.microsoft.com/fwlink/?linkid=2166289"
$FilePath = "C:\Program Files (x86)\Windows Kits\10\Vsix\VS2019\WDK.vsix"
$wdkSignatureThumbprint = "914A09C2E02C696AF394048BCB8D95449BCD5B9E" $wdkSignatureThumbprint = "914A09C2E02C696AF394048BCB8D95449BCD5B9E"
$winSdkSignatureThumbprint = "44796EB5BD439B4BFB078E1DC2F8345AE313CBB1" $wdkExtensionPath = "C:\Program Files (x86)\Windows Kits\10\Vsix\VS2019\WDK.vsix"
} elseif (Test-IsWin22) {
# SDK is available through Visual Studio
$wdkUrl = "https://go.microsoft.com/fwlink/?linkid=2249371"
$wdkSignatureThumbprint = "7C94971221A799907BB45665663BBFD587BAC9F8"
$wdkExtensionPath = "C:\Program Files (x86)\Windows Kits\10\Vsix\VS2022\*\WDK.vsix"
} else { } else {
throw "Invalid version of Visual Studio is found. Either 2019 or 2022 are required" throw "Invalid version of Visual Studio is found. Either 2019 or 2022 are required"
} }
$argumentList = ("/features", "+", "/quiet") # Install all features without showing the GUI using wdksetup.exe
Install-Binary -Type EXE `
if (Test-IsWin19) { -Url $wdkUrl `
# `winsdksetup.exe /features + /quiet` installs all features without showing the GUI -InstallArgs @("/features", "+", "/quiet") `
Install-Binary -Url $winSdkUrl -Name "winsdksetup.exe" -ArgumentList $argumentList -ExpectedSignature $winSdkSignatureThumbprint -ExpectedSignature $wdkSignatureThumbprint
}
# `wdksetup.exe /features + /quiet` installs all features without showing the GUI
Install-Binary -Url $wdkUrl -Name "wdksetup.exe" -ArgumentList $argumentList -ExpectedSignature $wdkSignatureThumbprint
# Need to install the VSIX to get the build targets when running VSBuild # Need to install the VSIX to get the build targets when running VSBuild
$FilePath = Resolve-Path -Path $FilePath $wdkExtensionPath = Resolve-Path -Path $wdkExtensionPath
Install-VsixExtension -FilePath $FilePath -Name "WDK.vsix" -InstallOnly Install-VsixExtension -FilePath $wdkExtensionPath -Name "WDK.vsix" -InstallOnly
Invoke-PesterTests -TestFile "WDK" Invoke-PesterTests -TestFile "WDK"

View File

@@ -3,10 +3,8 @@
## Desc: Install WebPlatformInstaller ## Desc: Install WebPlatformInstaller
################################################################################ ################################################################################
# Download and install WebPlatformInstaller Install-Binary -Type MSI `
$webPlatformInstallerFile = "WebPlatformInstaller_x64_en-US.msi" -Url 'http://go.microsoft.com/fwlink/?LinkId=287166' `
$webPlatformInstallerUrl = "http://go.microsoft.com/fwlink/?LinkId=287166" -ExpectedSignature 'C3A3D43788E7ABCD287CB4F5B6583043774F99D2'
$webPlatformInstallerSignatureThumbprint = "C3A3D43788E7ABCD287CB4F5B6583043774F99D2"
Install-Binary -Url $webPlatformInstallerUrl -Name $webPlatformInstallerFile -ExpectedSignature $webPlatformInstallerSignatureThumbprint
Invoke-PesterTests -TestFile "Tools" -TestName "WebPlatformInstaller" Invoke-PesterTests -TestFile "Tools" -TestName "WebPlatformInstaller"

View File

@@ -3,12 +3,13 @@
## Desc: Install Windows Application Driver (WinAppDriver) ## Desc: Install Windows Application Driver (WinAppDriver)
#################################################################################### ####################################################################################
$LatestReleaseUrl = 'https://api.github.com/repos/microsoft/WinAppDriver/releases/latest'
$InstallerUrl = (Invoke-RestMethod -Uri $LatestReleaseUrl).assets.browser_download_url
$InstallerName = "WindowsApplicationDriver.msi"
$InstallerSignatureThumbprint = "2485A7AFA98E178CB8F30C9838346B514AEA4769"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-Binary -Url $InstallerUrl -Name $InstallerName -ExpectedSignature $InstallerSignatureThumbprint
$latestReleaseUrl = 'https://api.github.com/repos/microsoft/WinAppDriver/releases/latest'
$installerUrl = (Invoke-RestMethod -Uri $latestReleaseUrl).assets.browser_download_url
Install-Binary `
-Url $installerUrl `
-ExpectedSignature '2485A7AFA98E178CB8F30C9838346B514AEA4769'
Invoke-PesterTests -TestFile "WinAppDriver" -TestName "WinAppDriver" Invoke-PesterTests -TestFile "WinAppDriver" -TestName "WinAppDriver"

View File

@@ -3,6 +3,6 @@
## Desc: Install WIX. ## Desc: Install WIX.
################################################################################ ################################################################################
Choco-Install -PackageName wixtoolset -ArgumentList "--force" Install-ChocoPackage wixtoolset -ArgumentList "--force"
Invoke-PesterTests -TestFile "Wix" Invoke-PesterTests -TestFile "Wix"

View File

@@ -1,4 +1,4 @@
function Choco-Install { function Install-ChocoPackage {
[CmdletBinding()] [CmdletBinding()]
param( param(
[Parameter(Mandatory)] [Parameter(Mandatory)]
@@ -9,8 +9,7 @@ function Choco-Install {
process { process {
$count = 1 $count = 1
while($true) while ($true) {
{
Write-Host "Running [#$count]: choco install $packageName -y $argumentList" Write-Host "Running [#$count]: choco install $packageName -y $argumentList"
choco install $packageName -y @argumentList --no-progress choco install $packageName -y @argumentList --no-progress
@@ -18,8 +17,7 @@ function Choco-Install {
if ($pkg) { if ($pkg) {
Write-Host "Package installed: $pkg" Write-Host "Package installed: $pkg"
break break
} } else {
else {
$count++ $count++
if ($count -ge $retryCount) { if ($count -ge $retryCount) {
Write-Host "Could not install $packageName after $count attempts" Write-Host "Could not install $packageName after $count attempts"
@@ -31,20 +29,7 @@ function Choco-Install {
} }
} }
function Send-RequestToChocolateyPackages { function Resolve-ChocoPackageVersion {
param(
[Parameter(Mandatory)]
[string] $FilterQuery,
[string] $Url = "https://community.chocolatey.org/api",
[int] $ApiVersion = 2
)
$response = Invoke-RestMethod "$Url/v$ApiVersion/Packages()?$filterQuery"
return $response
}
function Get-LatestChocoPackageVersion {
param( param(
[Parameter(Mandatory)] [Parameter(Mandatory)]
[string] $PackageName, [string] $PackageName,
@@ -56,10 +41,10 @@ function Get-LatestChocoPackageVersion {
[int]$versionNumbers[-1] += 1 [int]$versionNumbers[-1] += 1
$incrementedVersion = $versionNumbers -join "." $incrementedVersion = $versionNumbers -join "."
$filterQuery = "`$filter=(Id eq '$PackageName') and (IsPrerelease eq false) and (Version ge '$TargetVersion') and (Version lt '$incrementedVersion')" $filterQuery = "`$filter=(Id eq '$PackageName') and (IsPrerelease eq false) and (Version ge '$TargetVersion') and (Version lt '$incrementedVersion')"
$latestVersion = (Send-RequestToChocolateyPackages -FilterQuery $filterQuery).properties.Version | $latestVersion = (Invoke-RestMethod "https://community.chocolatey.org/api/v2/Packages()?$filterQuery").properties.Version |
Where-Object {$_ -Like "$TargetVersion.*" -or $_ -eq $TargetVersion} | Where-Object { $_ -Like "$TargetVersion.*" -or $_ -eq $TargetVersion } |
Sort-Object {[version]$_} | Sort-Object { [version]$_ } |
Select-Object -Last 1 Select-Object -Last 1
return $latestVersion return $latestVersion
} }

View File

@@ -34,9 +34,9 @@ Export-ModuleMember -Function @(
'Get-WinVersion' 'Get-WinVersion'
'Test-IsWin22' 'Test-IsWin22'
'Test-IsWin19' 'Test-IsWin19'
'Choco-Install' 'Install-ChocoPackage'
'Send-RequestToCocolateyPackages' 'Send-RequestToCocolateyPackages'
'Get-LatestChocoPackageVersion' 'Resolve-ChocoPackageVersion'
'Get-GitHubPackageDownloadUrl' 'Get-GitHubPackageDownloadUrl'
'Extract-7Zip' 'Extract-7Zip'
'Invoke-SBWithRetry' 'Invoke-SBWithRetry'

View File

@@ -1,94 +1,132 @@
function Install-Binary function Install-Binary {
{
<# <#
.SYNOPSIS .SYNOPSIS
A helper function to install executables. A function to install binaries from either a URL or a local path.
.DESCRIPTION .DESCRIPTION
Download and install .exe or .msi binaries from specified URL. This function downloads and installs .exe or .msi binaries from a specified URL or a local path. It also supports checking the binary's signature and SHA256/SHA512 sum before installation.
.PARAMETER Url .PARAMETER Url
The URL from which the binary will be downloaded. Required parameter. The URL from which the binary will be downloaded. This parameter is required if LocalPath is not specified.
.PARAMETER Name .PARAMETER LocalPath
The Name with which binary will be downloaded. Required parameter. The local path of the binary to be installed. This parameter is required if Url is not specified.
.PARAMETER ArgumentList .PARAMETER Type
The list of arguments that will be passed to the installer. Required for .exe binaries. The type of the binary to be installed. Valid values are "MSI" and "EXE". If not specified, the type is inferred from the file extension.
.PARAMETER InstallArgs
The list of arguments that will be passed to the installer. Cannot be used together with ExtraInstallArgs.
.PARAMETER ExtraInstallArgs
Additional arguments that will be passed to the installer. Cannot be used together with InstallArgs.
.PARAMETER ExpectedSignature
The expected signature of the binary. If specified, the binary's signature is checked before installation.
.PARAMETER ExpectedSHA256Sum
The expected SHA256 sum of the binary. If specified, the binary's SHA256 sum is checked before installation.
.PARAMETER ExpectedSHA512Sum
The expected SHA512 sum of the binary. If specified, the binary's SHA512 sum is checked before installation.
.EXAMPLE .EXAMPLE
Install-Binary -Url "https://go.microsoft.com/fwlink/p/?linkid=2083338" -Name "winsdksetup.exe" -ArgumentList ("/features", "+", "/quiet") -ExpectedSignature "XXXXXXXXXXXXXXXXXXXXXXXXXX" Install-Binary -Url "https://go.microsoft.com/fwlink/p/?linkid=2083338" -Type EXE -InstallArgs ("/features", "+", "/quiet") -ExpectedSignature "A5C7D5B7C838D5F89DDBEDB85B2C566B4CDA881F"
#> #>
Param Param
( (
[Parameter(Mandatory, ParameterSetName="Url")] [Parameter(Mandatory, ParameterSetName = "Url")]
[String] $Url, [String] $Url,
[Parameter(Mandatory, ParameterSetName="Url")] [Parameter(Mandatory, ParameterSetName = "LocalPath")]
[String] $Name, [String] $LocalPath,
[Parameter(Mandatory, ParameterSetName="LocalPath")] [ValidateSet("MSI", "EXE")]
[String] $FilePath, [String] $Type,
[String[]] $ArgumentList, [String[]] $InstallArgs,
[String[]] $ExpectedSignature [String[]] $ExtraInstallArgs,
[String[]] $ExpectedSignature,
[String] $ExpectedSHA256Sum,
[String] $ExpectedSHA512Sum
) )
if ($PSCmdlet.ParameterSetName -eq "LocalPath") if ($PSCmdlet.ParameterSetName -eq "LocalPath") {
{ if (-not (Test-Path -Path $LocalPath)) {
$name = Split-Path -Path $FilePath -Leaf throw "LocalPath parameter is specified, but the file does not exist."
} }
else if (-not $Type) {
{ $Type = ([System.IO.Path]::GetExtension($LocalPath)).Replace(".", "").ToUpper()
Write-Host "Downloading $Name..." if ($Type -ne "MSI" -and $Type -ne "EXE") {
$filePath = Start-DownloadWithRetry -Url $Url -Name $Name throw "LocalPath parameter is specified, but the file extension is not .msi or .exe. Please specify the Type parameter."
}
}
$filePath = $LocalPath
} else {
if (-not $Type) {
$Type = ([System.IO.Path]::GetExtension($Url)).Replace(".", "").ToUpper()
if ($Type -ne "MSI" -and $Type -ne "EXE") {
throw "Cannot determine the file type from the URL. Please specify the Type parameter."
}
}
$fileName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetRandomFileName()) + ".$Type".ToLower()
$filePath = Start-DownloadWithRetry -Url $Url -Name $fileName
} }
if ($PSBoundParameters.ContainsKey('ExpectedSignature')) if ($PSBoundParameters.ContainsKey('ExpectedSignature')) {
{ if ($ExpectedSignature) {
if ($ExpectedSignature)
{
Test-FileSignature -FilePath $filePath -ExpectedThumbprint $ExpectedSignature Test-FileSignature -FilePath $filePath -ExpectedThumbprint $ExpectedSignature
} } else {
else
{
throw "ExpectedSignature parameter is specified, but no signature is provided." throw "ExpectedSignature parameter is specified, but no signature is provided."
} }
} }
# MSI binaries should be installed via msiexec.exe if ($ExpectedSHA256Sum) {
$fileExtension = ([System.IO.Path]::GetExtension($Name)).Replace(".", "") $fileHash = (Get-FileHash -Path $filePath -Algorithm SHA256).Hash
if ($fileExtension -eq "msi") Use-ChecksumComparison $fileHash $ExpectedSHA256Sum
{
if (-not $ArgumentList)
{
$ArgumentList = ('/i', $filePath, '/QN', '/norestart')
}
$filePath = "msiexec.exe"
} }
try if ($ExpectedSHA512Sum) {
{ $fileHash = (Get-FileHash -Path $filePath -Algorithm SHA512).Hash
$installStartTime = Get-Date Use-ChecksumComparison $fileHash $ExpectedSHA512Sum
Write-Host "Starting Install $Name..." }
$process = Start-Process -FilePath $filePath -ArgumentList $ArgumentList -Wait -PassThru
$exitCode = $process.ExitCode if ($ExtraInstallArgs -and $InstallArgs) {
$installCompleteTime = [math]::Round(($(Get-Date) - $installStartTime).TotalSeconds, 2) throw "InstallArgs and ExtraInstallArgs parameters cannot be used together."
if ($exitCode -eq 0 -or $exitCode -eq 3010) }
{
Write-Host "Installation successful in $installCompleteTime seconds" if ($Type -eq "MSI") {
# MSI binaries should be installed via msiexec.exe
if ($ExtraInstallArgs) {
$InstallArgs = @('/i', $filePath, '/qn', '/norestart') + $ExtraInstallArgs
} elseif (-not $InstallArgs) {
Write-Host "No arguments provided for MSI binary. Using default arguments: /i, /qn, /norestart"
$InstallArgs = @('/i', $filePath, '/qn', '/norestart')
} }
else $filePath = "msiexec.exe"
{ } else {
Write-Host "Non zero exit code returned by the installation process: $exitCode" # EXE binaries should be started directly
Write-Host "Total time elapsed: $installCompleteTime seconds" if ($ExtraInstallArgs) {
exit $exitCode $InstallArgs = $ExtraInstallArgs
} }
} }
catch
{ $installStartTime = Get-Date
Write-Host "Starting Install $Name..."
try {
$process = Start-Process -FilePath $filePath -ArgumentList $InstallArgs -Wait -PassThru
$exitCode = $process.ExitCode
$installCompleteTime = [math]::Round(($(Get-Date) - $installStartTime).TotalSeconds, 2) $installCompleteTime = [math]::Round(($(Get-Date) - $installStartTime).TotalSeconds, 2)
Write-Host "Failed to install the $fileExtension ${Name}: $($_.Exception.Message)" if ($exitCode -eq 0) {
Write-Host "Installation failed after $installCompleteTime seconds" Write-Host "Installation successful in $installCompleteTime seconds"
exit 1 } elseif ($exitCode -eq 3010) {
Write-Host "Installation successful in $installCompleteTime seconds. Reboot is required."
} else {
Write-Host "Installation process returned unexpected exit code: $exitCode"
Write-Host "Time elapsed: $installCompleteTime seconds"
exit $exitCode
}
} catch {
$installCompleteTime = [math]::Round(($(Get-Date) - $installStartTime).TotalSeconds, 2)
Write-Host "Installation failed in $installCompleteTime seconds"
} }
} }
@@ -171,8 +209,7 @@ function Set-SvcWithErrHandling {
} }
} }
function Start-DownloadWithRetry function Start-DownloadWithRetry {
{
Param Param
( (
[Parameter(Mandatory)] [Parameter(Mandatory)]
@@ -190,26 +227,20 @@ function Start-DownloadWithRetry
$downloadStartTime = Get-Date $downloadStartTime = Get-Date
# Default retry logic for the package. # Default retry logic for the package.
while ($Retries -gt 0) Write-Host "Downloading package from: $Url to path $filePath."
{ while ($Retries -gt 0) {
try try {
{
$downloadAttemptStartTime = Get-Date $downloadAttemptStartTime = Get-Date
Write-Host "Downloading package from: $Url to path $filePath ."
(New-Object System.Net.WebClient).DownloadFile($Url, $filePath) (New-Object System.Net.WebClient).DownloadFile($Url, $filePath)
break break
} } catch {
catch
{
$failTime = [math]::Round(($(Get-Date) - $downloadStartTime).TotalSeconds, 2) $failTime = [math]::Round(($(Get-Date) - $downloadStartTime).TotalSeconds, 2)
$attemptTime = [math]::Round(($(Get-Date) - $downloadAttemptStartTime).TotalSeconds, 2) $attemptTime = [math]::Round(($(Get-Date) - $downloadAttemptStartTime).TotalSeconds, 2)
Write-Host "There is an error encounterd after $attemptTime seconds during package downloading:`n $_" Write-Host "There is an error encounterd after $attemptTime seconds during package downloading:`n$($_.Exception.ToString())"
$Retries-- $Retries--
if ($Retries -eq 0) if ($Retries -eq 0) {
{ Write-Host "Package download failed after $failTime seconds"
Write-Host "File can't be downloaded. Please try later or check that file exists by url: $Url"
Write-Host "Total time elapsed $failTime"
exit 1 exit 1
} }

View File

@@ -66,14 +66,19 @@ Function Install-VisualStudio {
$responseDataPath = "$env:TEMP\vs_install_response.json" $responseDataPath = "$env:TEMP\vs_install_response.json"
$responseData | ConvertTo-Json | Out-File -FilePath $responseDataPath $responseData | ConvertTo-Json | Out-File -FilePath $responseDataPath
$installStartTime = Get-Date
Write-Host "Starting Install ..." Write-Host "Starting Install ..."
$bootstrapperArgumentList = ('/c', $bootstrapperFilePath, '--in', $responseDataPath, $ExtraArgs, '--quiet', '--norestart', '--wait', '--nocache' ) $bootstrapperArgumentList = ('/c', $bootstrapperFilePath, '--in', $responseDataPath, $ExtraArgs, '--quiet', '--norestart', '--wait', '--nocache' )
Write-Host "Bootstrapper arguments: $bootstrapperArgumentList" Write-Host "Bootstrapper arguments: $bootstrapperArgumentList"
$process = Start-Process -FilePath cmd.exe -ArgumentList $bootstrapperArgumentList -Wait -PassThru $process = Start-Process -FilePath cmd.exe -ArgumentList $bootstrapperArgumentList -Wait -PassThru
$exitCode = $process.ExitCode $exitCode = $process.ExitCode
if ($exitCode -eq 0 -or $exitCode -eq 3010) { $installCompleteTime = [math]::Round(($(Get-Date) - $installStartTime).TotalSeconds, 2)
Write-Host "Installation successful" if ($exitCode -eq 0) {
Write-Host "Installation successful in $installCompleteTime seconds"
return $exitCode
} elseif ($exitCode -eq 3010) {
Write-Host "Installation successful in $installCompleteTime seconds. Reboot is required."
return $exitCode return $exitCode
} else { } else {
Write-Host "Non zero exit code returned by the installation process : $exitCode" Write-Host "Non zero exit code returned by the installation process : $exitCode"