Skip to content

Commit

Permalink
feat(curl): add retries and timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Oct 7, 2024
1 parent 9a3209f commit 2c973db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/playbook/Executables/LIBREWOLF.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down
17 changes: 9 additions & 8 deletions src/playbook/Executables/SOFTWARE.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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
}
Expand All @@ -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..."
Expand Down Expand Up @@ -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..."
Expand Down

0 comments on commit 2c973db

Please sign in to comment.