diff --git a/images/win/scripts/Installers/Install-CloudFoundryCli.ps1 b/images/win/scripts/Installers/Install-CloudFoundryCli.ps1 index cc1f0b5c29c8..194ed5a3867b 100644 --- a/images/win/scripts/Installers/Install-CloudFoundryCli.ps1 +++ b/images/win/scripts/Installers/Install-CloudFoundryCli.ps1 @@ -6,19 +6,18 @@ Import-Module -Name ImageHelpers # Download the latest cf cli exe -Invoke-WebRequest -UseBasicParsing -Uri "https://packages.cloudfoundry.org/stable?release=windows64-exe&source=github" -OutFile cf-cli.zip +$CloudFoundryCliName = "cf-cli.zip" +$CloudFoundryCliUrl = "https://packages.cloudfoundry.org/stable?release=windows64-exe&source=github" + +$CloudFoundryArchPath = Start-DownloadWithRetry -Url $CloudFoundryCliUrl -Name $CloudFoundryCliName # Create directory for cf cli -$cf_cli_path = "C:\cf-cli" -New-Item -Path $cf_cli_path -ItemType Directory -Force +$CloudFoundryCliPath = "C:\cf-cli" +New-Item -Path $CloudFoundryCliPath -ItemType Directory -Force # Extract the zip archive Write-Host "Extracting cf cli..." -Expand-Archive -Path cf-cli.zip -DestinationPath $cf_cli_path -Force +Expand-Archive -Path $CloudFoundryArchPath -DestinationPath $CloudFoundryCliPath -Force # Add cf to path -Add-MachinePathItem $cf_cli_path - -# Delete the cfl-cli zip archive -Write-Host "Deleting downloaded archive of cf cli" -Remove-Item cf-cli.zip +Add-MachinePathItem $CloudFoundryCliPath \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-Go.ps1 b/images/win/scripts/Installers/Install-Go.ps1 index db186186d8ea..6d98ef800f30 100644 --- a/images/win/scripts/Installers/Install-Go.ps1 +++ b/images/win/scripts/Installers/Install-Go.ps1 @@ -6,12 +6,13 @@ Import-Module -Name ImageHelpers -Force $refsJson = Invoke-RestMethod "https://api.github.com/repos/golang/go/git/refs/tags" + function Install-GoVersion { Param ( - [String]$goVersion, - [Switch]$addToDefaultPath + [String] $goVersion, + [Switch] $addToDefaultPath ) $latestVersionObject = $refsJson | Where-Object { $_.ref -Match "refs/tags/go$goVersion[./d]*" } | Select-Object -Last 1 @@ -20,11 +21,15 @@ function Install-GoVersion # Download the Go zip archive. Write-Host "Downloading Go $latestVersion..." $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest -UseBasicParsing -Uri "https://dl.google.com/go/go$latestVersion.windows-amd64.zip" -OutFile go$latestVersion.windows-amd64.zip + + $goArchName = "go${latestVersion}.windows-amd64.zip" + $goArchUrl = "https://dl.google.com/go/${goArchName}" + + $goArchPath = Start-DownloadWithRetry -Url $goArchUrl -Name $goArchName # Extract the zip archive. It contains a single directory named "go". Write-Host "Extracting Go $latestVersion..." - Expand-Archive -Path go$latestVersion.windows-amd64.zip -DestinationPath "C:\" -Force + Expand-Archive -Path $goArchPath -DestinationPath "C:\" -Force # Delete unnecessary files to conserve space Write-Host "Cleaning directories of Go $latestVersion..." @@ -41,10 +46,6 @@ function Install-GoVersion $newDirName = "Go$latestVersion" Rename-Item -path "C:\go" -newName $newDirName - # Delete the Go zip archive. - Write-Host "Deleting downloaded archive of Go $latestVersion..." - Remove-Item go$latestVersion.windows-amd64.zip - # Make this the default version of Go? if ($addToDefaultPath) { @@ -63,13 +64,18 @@ function Install-GoVersion # Install Go $goVersionsToInstall = $env:GO_VERSIONS.split(", ", [System.StringSplitOptions]::RemoveEmptyEntries) -foreach($go in $goVersionsToInstall) { +foreach ($go in $goVersionsToInstall) +{ Write-Host "Installing Go ${go}" - if($go -eq $env:GO_DEFAULT) { + if ($go -eq $env:GO_DEFAULT) + { $installDirectory = Install-GoVersion -goVersion $go -addToDefaultPath - } else { + } + else + { $installDirectory = Install-GoVersion -goVersion $go } + $envName = "GOROOT_{0}_{1}_X64" -f $go.split(".") setx $envName "$installDirectory" /M } diff --git a/images/win/scripts/Installers/Install-Kind.ps1 b/images/win/scripts/Installers/Install-Kind.ps1 index 6093049b35f6..12f0caa04cb2 100644 --- a/images/win/scripts/Installers/Install-Kind.ps1 +++ b/images/win/scripts/Installers/Install-Kind.ps1 @@ -6,25 +6,24 @@ $stableKindTag = "v0.7.0" $tagToUse = $stableKindTag; $destFilePath = "C:\ProgramData\kind" -$outFilePath = "C:\ProgramData\kind\kind.exe" try { - $getkindUri = "https://github.com/kubernetes-sigs/kind/releases/download/$tagToUse/kind-windows-amd64" + $kindUrl = "https://github.com/kubernetes-sigs/kind/releases/download/$tagToUse/kind-windows-amd64" + Write-Host "Downloading kind.exe..." New-Item -Path $destFilePath -ItemType Directory -Force - Invoke-WebRequest -Uri $getkindUri -OutFile $outFilePath + $kindInstallerPath = Start-DownloadWithRetry -Url $kindUrl -Name "kind.exe" -DownloadPath $destFilePath Write-Host "Starting Install kind.exe..." - $process = Start-Process -FilePath $outFilePath -Wait -PassThru + $process = Start-Process -FilePath $kindInstallerPath -Wait -PassThru $exitCode = $process.ExitCode if ($exitCode -eq 0 -or $exitCode -eq 3010) { Write-Host -Object 'Installation successful' Add-MachinePathItem $destFilePath - exit $exitCode } else { diff --git a/images/win/scripts/Installers/Install-MysqlCli.ps1 b/images/win/scripts/Installers/Install-MysqlCli.ps1 index 348657d747de..a9db2f4295ed 100644 --- a/images/win/scripts/Installers/Install-MysqlCli.ps1 +++ b/images/win/scripts/Installers/Install-MysqlCli.ps1 @@ -3,10 +3,10 @@ ## Desc: Install Mysql CLI ################################################################################ - ## Downloading mysql jar -$uri = 'https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-winx64.zip' -$mysqlPath = 'C:\mysql-5.7.21-winx64\bin' +$MysqlVersionName = "mysql-5.7.21-winx64" +$MysqlVersionUrl = "https://dev.mysql.com/get/Downloads/MySQL-5.7/${MysqlVersionName}.zip" +$MysqlPath = "C:\$MysqlVersionName\bin" # Installing visual c++ redistibutable package. $InstallerName = "vcredist_x64.exe" @@ -19,13 +19,10 @@ Install-Binary -Url $InstallerURI -Name $InstallerName -ArgumentList $ArgumentLi [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor "Tls12" # Get the latest mysql command line tools . -Invoke-WebRequest -UseBasicParsing -Uri $uri -OutFile mysql.zip +$mysqlArchPath = Start-DownloadWithRetry -Url $MysqlVersionUrl -Name "mysql.zip" # Expand the zip -Expand-Archive -Path mysql.zip -DestinationPath "C:\" -Force - -# Deleting zip folder -Remove-Item -Recurse -Force mysql.zip +Expand-Archive -Path $mysqlArchPath -DestinationPath "C:\" -Force # Adding mysql in system environment path Add-MachinePathItem $mysqlPath \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-Rust.ps1 b/images/win/scripts/Installers/Install-Rust.ps1 index 61588a86f9ab..ae18371afddf 100644 --- a/images/win/scripts/Installers/Install-Rust.ps1 +++ b/images/win/scripts/Installers/Install-Rust.ps1 @@ -11,13 +11,10 @@ $env:CARGO_HOME="C:\Rust\.cargo" # Download the latest rustup-init.exe for Windows x64 # See https://rustup.rs/# -Invoke-WebRequest -UseBasicParsing -Uri "https://win.rustup.rs/x86_64" -OutFile rustup-init.exe +$rustupPath = Start-DownloadWithRetry -Url "https://win.rustup.rs/x86_64" -Name "rustup-init.exe" # Install Rust by running rustup-init.exe (disabling the confirmation prompt with -y) -.\rustup-init.exe -y --default-toolchain=stable --profile=minimal - -# Delete rustup-init.exe when it's no longer needed -Remove-Item -Path .\rustup-init.exe +& $rustupPath -y --default-toolchain=stable --profile=minimal # Add Rust binaries to the path Add-MachinePathItem "$env:CARGO_HOME\bin" diff --git a/images/win/scripts/Installers/Install-SQLPowerShellTools.ps1 b/images/win/scripts/Installers/Install-SQLPowerShellTools.ps1 index bf330f6907e7..8369a9944fe0 100644 --- a/images/win/scripts/Installers/Install-SQLPowerShellTools.ps1 +++ b/images/win/scripts/Installers/Install-SQLPowerShellTools.ps1 @@ -5,57 +5,21 @@ Import-Module -Name ImageHelpers -Force -Function InstallMSI -{ - Param - ( - [String]$MsiUrl, - [String]$MsiName - ) - - $exitCode = -1 - - try - { - Write-Host "Downloading $MsiName..." - $FilePath = "${env:Temp}\$MsiName" - - Invoke-WebRequest -Uri $MsiUrl -OutFile $FilePath - - $Arguments = ('/i', $FilePath, '/QN', '/norestart' ) - - Write-Host "Starting Install $MsiName..." - $process = Start-Process -FilePath msiexec.exe -ArgumentList $Arguments -Wait -PassThru - $exitCode = $process.ExitCode - - if ($exitCode -eq 0 -or $exitCode -eq 3010) - { - Write-Host -Object 'Installation successful' - return $exitCode - } - else - { - Write-Host -Object "Non zero exit code returned by the installation process : $exitCode." - exit $exitCode - } - } - catch - { - Write-Host -Object "Failed to install the MSI $MsiName" - Write-Host -Object $_.Exception.Message - exit -1 - } -} +$BaseUrl = "https://download.microsoft.com/download/8/7/2/872BCECA-C849-4B40-8EBE-21D48CDF1456/ENU/x64" # install required MSIs -$SQLSysClrTypesExitCode = InstallMSI -MsiUrl "https://download.microsoft.com/download/8/7/2/872BCECA-C849-4B40-8EBE-21D48CDF1456/ENU/x64/SQLSysClrTypes.msi" -MsiName "SQLSysClrTypes.msi" +$SQLSysClrTypesName = "SQLSysClrTypes.msi" +$SQLSysClrTypesUrl = "${BaseUrl}/${SQLSysClrTypesName}" +Install-Binary -Url $SQLSysClrTypesUrl -Name $SQLSysClrTypesName -$SharedManagementObjectsExitCode = InstallMSI -MsiUrl "https://download.microsoft.com/download/8/7/2/872BCECA-C849-4B40-8EBE-21D48CDF1456/ENU/x64/SharedManagementObjects.msi" -MsiName "SharedManagementObjects.msi" +$SharedManagementObjectsName = "SharedManagementObjects.msi" +$SharedManagementObjectsUrl = "${BaseUrl}/${SharedManagementObjectsName}" +Install-Binary -Url $SharedManagementObjectsUrl -Name $SharedManagementObjectsName -$PowerShellToolsExitCode = InstallMSI -MsiUrl "https://download.microsoft.com/download/8/7/2/872BCECA-C849-4B40-8EBE-21D48CDF1456/ENU/x64/PowerShellTools.msi" -MsiName "PowerShellTools.msi" +$PowerShellToolsName = "PowerShellTools.msi" +$PowerShellToolsUrl = "${BaseUrl}/${PowerShellToolsName}" +Install-Binary -Url $PowerShellToolsUrl -Name $PowerShellToolsName # install sqlserver PS module Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -Install-Module -Name SqlServer -AllowClobber - -exit $PowerShellToolsExitCode +Install-Module -Name SqlServer -AllowClobber \ No newline at end of file diff --git a/images/win/scripts/Installers/Update-AndroidSDK.ps1 b/images/win/scripts/Installers/Update-AndroidSDK.ps1 index 4a04b0b6f6f5..0e35c27a77fa 100644 --- a/images/win/scripts/Installers/Update-AndroidSDK.ps1 +++ b/images/win/scripts/Installers/Update-AndroidSDK.ps1 @@ -5,10 +5,10 @@ # Download the latest command line tools so that we can accept all of the licenses. # See https://developer.android.com/studio/#command-tools -Invoke-WebRequest -UseBasicParsing -Uri "https://dl.google.com/android/repository/sdk-tools-windows-4333796.zip" -OutFile android-sdk-tools.zip +$sdkArchPath = Start-DownloadWithRetry -Url "https://dl.google.com/android/repository/sdk-tools-windows-4333796.zip" -Name "android-sdk-tools.zip" # Don't replace the one that VS installs as it seems to break things. -Expand-Archive -Path android-sdk-tools.zip -DestinationPath android-sdk -Force +Expand-Archive -Path $sdkArchPath -DestinationPath android-sdk -Force $sdk = Get-Item -Path .\android-sdk