Skip to content

Commit

Permalink
feat(LIBREWOLF): reliability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Aug 11, 2024
1 parent 5e62c60 commit 5065610
Showing 1 changed file with 29 additions and 34 deletions.
63 changes: 29 additions & 34 deletions src/playbook/Executables/LIBREWOLF.ps1
Original file line number Diff line number Diff line change
@@ -1,70 +1,65 @@
$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

# Output paths
$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

0 comments on commit 5065610

Please sign in to comment.