From 2c973db567416a96967f67aea91457fb2448bbbf Mon Sep 17 00:00:00 2001 From: he3als <65787561+he3als@users.noreply.github.com> Date: Mon, 7 Oct 2024 18:52:22 +0100 Subject: [PATCH] feat(curl): add retries and timeouts --- src/playbook/Executables/LIBREWOLF.ps1 | 5 +++-- src/playbook/Executables/SOFTWARE.ps1 | 17 +++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/playbook/Executables/LIBREWOLF.ps1 b/src/playbook/Executables/LIBREWOLF.ps1 index b986043845..8346fcfce8 100644 --- a/src/playbook/Executables/LIBREWOLF.ps1 +++ b/src/playbook/Executables/LIBREWOLF.ps1 @@ -1,6 +1,7 @@ .\AtlasModules\initPowerShell.ps1 $ProgressPreference = "SilentlyContinue" $ErrorActionPreference = "Stop" +$timeouts = @("--connect-timeout", "5", "--max-time", "10", "--retry", "5", "--retry-delay", "0", "--retry-max-time", "40", "--retry-all-errors") # Initial variables $drive = Get-SystemDrive @@ -21,7 +22,7 @@ $librewolfDownload = "https://gitlab.com/api/v4/projects/$gitLabId/packages/gene Write-Output "Downloading the latest LibreWolf setup" $outputLibrewolf = "$drive\$librewolfFileName" -curl.exe -LSs "$librewolfDownload" -o "$outputLibrewolf" +curl.exe -LSs "$librewolfDownload" -o "$outputLibrewolf" $timeouts Write-Output "Installing LibreWolf silently" Start-Process -Wait -FilePath $outputLibrewolf -ArgumentList "/S" @@ -42,7 +43,7 @@ $librewolfUpdaterDownload = (Invoke-RestMethod -Uri "$librewolfUpdaterURI").Asse Write-Output "Downloading the latest LibreWolf WinUpdater ZIP" $outputLibrewolfUpdater = "$drive\librewolf-winupdater.zip" -curl.exe -LSs "$librewolfUpdaterDownload" -o "$outputLibrewolfUpdater" +curl.exe -LSs "$librewolfUpdaterDownload" -o "$outputLibrewolfUpdater" $timeouts Write-Output "Extracting Librewolf-WinUpdater" Expand-Archive -Path $outputLibrewolfUpdater -DestinationPath "$programs\LibreWolf\librewolf-winupdater" -Force diff --git a/src/playbook/Executables/SOFTWARE.ps1 b/src/playbook/Executables/SOFTWARE.ps1 index c5da950949..60f9fdfbeb 100644 --- a/src/playbook/Executables/SOFTWARE.ps1 +++ b/src/playbook/Executables/SOFTWARE.ps1 @@ -10,6 +10,7 @@ param ( # Software is no longer installed with a package manager anymore to be as fast and as reliable as possible. # # ----------------------------------------------------------------------------------------------------------- # +$timeouts = @("--connect-timeout", "5", "--max-time", "10", "--retry", "5", "--retry-delay", "0", "--retry-max-time", "40", "--retry-all-errors") $msiArgs = "/qn /quiet /norestart ALLUSERS=1 REBOOT=ReallySuppress" $arm = ((Get-CimInstance -Class Win32_ComputerSystem).SystemType -match 'ARM64') -or ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') @@ -22,7 +23,7 @@ Push-Location $tempDir # Brave if ($Brave) { Write-Output "Downloading Brave..." - & curl.exe -LSs "https://laptop-updates.brave.com/latest/winx64" -o "$tempDir\BraveSetup.exe" + & curl.exe -LSs "https://laptop-updates.brave.com/latest/winx64" -o "$tempDir\BraveSetup.exe" $timeouts if (!$?) { Write-Error "Downloading Brave failed." exit 1 @@ -50,10 +51,10 @@ if ($Firefox) { $firefoxArch = ('win64', 'win64-aarch64')[$arm] Write-Output "Downloading Firefox..." - & curl.exe -LSs "https://download.mozilla.org/?product=firefox-latest-ssl&os=$firefoxArch&lang=en-US" -o "$tempDir\firefox.exe" + & curl.exe -LSs "https://download.mozilla.org/?product=firefox-latest-ssl&os=$firefoxArch&lang=en-US" -o "$tempDir\firefox.exe" $timeouts Write-Output "Installing Firefox..." Start-Process -FilePath "$tempDir\firefox.exe" -WindowStyle Hidden -ArgumentList '/S /ALLUSERS=1' -Wait - + Remove-TempDirectory exit } @@ -62,7 +63,7 @@ if ($Firefox) { if ($Chrome) { Write-Output "Downloading Google Chrome..." $chromeArch = ('64', '_Arm64')[$arm] - & curl.exe -LSs "https://dl.google.com/dl/chrome/install/googlechromestandaloneenterprise$chromeArch.msi" -o "$tempDir\chrome.msi" + & curl.exe -LSs "https://dl.google.com/dl/chrome/install/googlechromestandaloneenterprise$chromeArch.msi" -o "$tempDir\chrome.msi" $timeouts Write-Output "Installing Google Chrome..." Start-Process -FilePath "$tempDir\chrome.msi" -WindowStyle Hidden -ArgumentList '/qn' -Wait @@ -107,7 +108,7 @@ foreach ($a in $vcredists.GetEnumerator()) { # curl is faster than Invoke-WebRequest Write-Output "Downloading and installing Visual C++ Runtime $vcName..." - & curl.exe -LSs "$vcUrl" -o "$vcExePath" + & curl.exe -LSs "$vcUrl" -o "$vcExePath" $timeouts if ($vcArgs -match ":") { $msiDir = "$tempDir\vcredist-$vcName" @@ -132,7 +133,7 @@ function Install7Zip { $7zipArch = ('x64', 'arm64')[$arm] $download = $website + ((Invoke-WebRequest $website -UseBasicParsing).Links.href | Where-Object { $_ -like "a/7z*-$7zipArch.exe" }) Write-Output "Downloading 7-Zip..." - & curl.exe -LSs $download -o "$tempDir\7zip.exe" + & curl.exe -LSs $download -o "$tempDir\7zip.exe" $timeouts Write-Output "Installing 7-Zip..." Start-Process -FilePath "$tempDir\7zip.exe" -WindowStyle Hidden -ArgumentList '/S' -Wait } @@ -145,7 +146,7 @@ function InstallNanaZip { $assets | ForEach-Object { $filename = $_ -split '/' | Select-Object -Last 1 Write-Output "Downloading '$filename'..." - & curl.exe -LSs $_ -o "$path\$filename" + & curl.exe -LSs $_ -o "$path\$filename" $timeouts } Write-Output "Installing NanaZip..." @@ -187,7 +188,7 @@ NanaZip is a fork of 7-Zip with an updated user interface and extra features. } # Legacy DirectX runtimes -& curl.exe -LSs "https://download.microsoft.com/download/8/4/A/84A35BF1-DAFE-4AE8-82AF-AD2AE20B6B14/directx_Jun2010_redist.exe" -o "$tempDir\directx.exe" +& curl.exe -LSs "https://download.microsoft.com/download/8/4/A/84A35BF1-DAFE-4AE8-82AF-AD2AE20B6B14/directx_Jun2010_redist.exe" -o "$tempDir\directx.exe" $timeouts Write-Output "Extracting legacy DirectX runtimes..." Start-Process -FilePath "$tempDir\directx.exe" -WindowStyle Hidden -ArgumentList "/q /c /t:`"$tempDir\directx`"" -Wait Write-Output "Installing legacy DirectX runtimes..."