From 5065610d03b61451e479ff3d3d8e56b11b69b0ec Mon Sep 17 00:00:00 2001 From: he3als <65787561+he3als@users.noreply.github.com> Date: Sun, 11 Aug 2024 18:42:57 +0100 Subject: [PATCH] feat(LIBREWOLF): reliability improvements --- src/playbook/Executables/LIBREWOLF.ps1 | 63 ++++++++++++-------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/src/playbook/Executables/LIBREWOLF.ps1 b/src/playbook/Executables/LIBREWOLF.ps1 index 7821790382..f2cf0940d4 100644 --- a/src/playbook/Executables/LIBREWOLF.ps1 +++ b/src/playbook/Executables/LIBREWOLF.ps1 @@ -1,23 +1,26 @@ $ProgressPreference = "SilentlyContinue" $ErrorActionPreference = "Stop" -# Define variables +# Initial variables +$env:PSModulePath += ";$PWD\AtlasModules\Scripts\Modules" $desktop = [Environment]::GetFolderPath("Desktop") $startMenu = [Environment]::GetFolderPath("CommonPrograms") $programs = [Environment]::GetFolderPath("ProgramFiles") $updaterPath = "$programs\LibreWolf\librewolf-winupdater" $librewolfPath = "$programs\LibreWolf" -# Get latest LibreWolf download link Write-Output "Getting the latest LibreWolf download link" -$librewolfVersion = Invoke-RestMethod -Uri "https://gitlab.com/api/v4/projects/44042130/releases" | ForEach-Object { $_.name } | Select-Object -First 1 +$gitLabId = '44042130' +$librewolfVersion = (Invoke-RestMethod "https://gitlab.com/api/v4/projects/$gitLabId/releases")[0].Name +if ([string]::IsNullOrEmpty($librewolfVersion)) { + throw "GitLab API returned nothing!" +} $librewolfFileName = "librewolf-$librewolfVersion-windows-x86_64-setup.exe" -$librewolfDownload = "https://gitlab.com/api/v4/projects/44042130/packages/generic/librewolf/$librewolfVersion/$librewolfFileName" +$librewolfDownload = "https://gitlab.com/api/v4/projects/$gitLabId/packages/generic/librewolf/$librewolfVersion/$librewolfFileName" -# Get latest LibreWolf-WinUpdater download link Write-Output "Getting the latest LibreWolf-WinUpdater download link" $librewolfUpdaterURI = "https://codeberg.org/api/v1/repos/ltguillaume/librewolf-winupdater/releases?draft=false&pre-release=false&page=1&limit=1" -$librewolfUpdaterDownload = (Invoke-RestMethod -Uri "$librewolfUpdaterURI" -Headers @{ "accept" = "application/json" }).Assets | +$librewolfUpdaterDownload = (Invoke-RestMethod -Uri "$librewolfUpdaterURI").Assets | Where-Object { $_.name -like "*.zip" } | Select-Object -ExpandProperty browser_download_url @@ -25,46 +28,38 @@ $librewolfUpdaterDownload = (Invoke-RestMethod -Uri "$librewolfUpdaterURI" -Head $outputLibrewolf = "$env:systemdrive\$librewolfFileName" $outputLibrewolfUpdater = "$env:systemdrive\librewolf-winupdater.zip" -# Download files Write-Output "Downloading the latest LibreWolf setup" curl.exe -LSs "$librewolfDownload" -o "$outputLibrewolf" -Write-Output "Downloading the latest LibreWolf WinUpdater ZIP" -curl.exe -LSs "$librewolfUpdaterDownload" -o "$outputLibrewolfUpdater" -# Install LibreWolf & LibreWolf-WinUpdater Write-Output "Installing LibreWolf silently" Start-Process -Wait -FilePath $outputLibrewolf -ArgumentList "/S" if (!(Test-Path $librewolfPath)) { - Write-Host "Installing LibreWolf silently failed." - exit 1 + throw "Installing LibreWolf silently failed." } + +Write-Output "Creating LibreWolf Desktop shortcut" +New-Shortcut -Source "$librewolfPath\librewolf.exe" -ShortcutPath "$desktop\LibreWolf.lnk" -WorkingDir $librewolfPath + +Write-Output "Downloading the latest LibreWolf WinUpdater ZIP" +curl.exe -LSs "$librewolfUpdaterDownload" -o "$outputLibrewolfUpdater" + Write-Output "Installing/extracting Librewolf-WinUpdater" -Expand-Archive -Path $outputLibrewolfUpdater -DestinationPath "$env:programfiles\LibreWolf\librewolf-winupdater" -Force +Expand-Archive -Path $outputLibrewolfUpdater -DestinationPath "$programs\LibreWolf\librewolf-winupdater" -Force # Automatic updater Write-Output "Adding automatic updater task" -$Action = New-ScheduledTaskAction -Execute "$updaterPath\LibreWolf-WinUpdater.exe" -Argument "/Scheduled" -$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -RunOnlyIfNetworkAvailable -$7Hours = New-ScheduledTaskTrigger -Once -At (Get-Date -Minute 0 -Second 0).AddHours(1) -RepetitionInterval (New-TimeSpan -Hours 7) -$AtLogon = New-ScheduledTaskTrigger -AtLogOn -$AtLogon.Delay = 'PT1M' -$User = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name -Register-ScheduledTask -TaskName "LibreWolf WinUpdater ($($User -replace ".*\\"))" -Action $Action -Settings $Settings -Trigger $7Hours,$AtLogon -User $User -RunLevel Highest -Force | Out-Null - -# Shortcuts -Write-Output "Creating shortcuts" -function Add-Shortcut { - param ( [string]$Source, [string]$Destination, [string]$WorkingDir ) - $WshShell = New-Object -comObject WScript.Shell - $Shortcut = $WshShell.CreateShortcut($Destination) - $Shortcut.TargetPath = $Source - $Shortcut.WorkingDirectory = $WorkingDir - $Shortcut.Save() +foreach ($User in (Get-CimInstance -ClassName Win32_UserAccount -Filter "Disabled=False").Name) { + $Action = New-ScheduledTaskAction -Execute "$updaterPath\LibreWolf-WinUpdater.exe" -Argument "/Scheduled" + $Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -RunOnlyIfNetworkAvailable + $7Hours = New-ScheduledTaskTrigger -Once -At (Get-Date -Minute 0 -Second 0).AddHours(1) -RepetitionInterval (New-TimeSpan -Hours 7) + $AtLogon = New-ScheduledTaskTrigger -AtLogOn + $AtLogon.Delay = 'PT1M' + Register-ScheduledTask -TaskName "LibreWolf WinUpdater ($User)" -Action $Action -Settings $Settings -Trigger $7Hours,$AtLogon -User $User -RunLevel Highest -Force | Out-Null } -Add-Shortcut -Source "$librewolfPath\librewolf.exe" -Destination "$desktop\LibreWolf.lnk" -WorkingDir $librewolfPath -Add-Shortcut -Source "$updaterPath\Librewolf-WinUpdater.exe" -Destination "$startMenu\LibreWolf\LibreWolf WinUpdater.lnk" -WorkingDir $librewolfPath -# Temp files -Write-Output "Removing temporary installer files" +Write-Output "Adding LibreWolf WinUpdater shortcut" +New-Shortcut -Source "$updaterPath\Librewolf-WinUpdater.exe" -ShortcutPath "$startMenu\LibreWolf\LibreWolf WinUpdater.lnk" -WorkingDir $librewolfPath + +Write-Output "Removing temp files" Remove-Item "$outputLibrewolf" -Force Remove-Item "$outputLibrewolfUpdater" -Force \ No newline at end of file