Skip to content

Commit

Permalink
refactor(librewolf): use param block instead
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Oct 2, 2023
1 parent 25ec88a commit 5b655d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/playbook/Configuration/atlas/start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ actions:
option: 'librewolf-winupdater'
- !run:
exe: 'powershell.exe'
args: '-NoP -File "LIBREWOLF.ps1" noupdater'
args: '-NoP -File "LIBREWOLF.ps1" -NoUpdater'
exeDir: true
wait: true
weight: 150
Expand Down
20 changes: 12 additions & 8 deletions src/playbook/Executables/LIBREWOLF.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
param (
[switch]$NoUpdater
)

# disable progress bars
$ProgressPreference = "SilentlyContinue"
# stop on errors, as each command is vital
$ErrorActionPreference = "Stop"

if ($args -ne 'noupdater') { $updaterPath = "$env:ProgramFiles\LibreWolf\librewolf-winupdater" }
if ($NoUpdater) { $updaterPath = "$env:ProgramFiles\LibreWolf\librewolf-winupdater" }
$librewolfPath = "$env:ProgramFiles\LibreWolf"
$desktop = [Environment]::GetFolderPath("Desktop")
$startMenu = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs"
Expand All @@ -18,7 +22,7 @@ Write-Warning "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
$librewolfFileName = "librewolf-$librewolfVersion-windows-x86_64-setup.exe"
$librewolfDownload = "https://gitlab.com/api/v4/projects/44042130/packages/generic/librewolf/$librewolfVersion/$librewolfFileName"
if ($args -ne 'noupdater') {
if ($NoUpdater) {
Write-Warning "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 |
Expand All @@ -27,11 +31,11 @@ if ($args -ne 'noupdater') {
}
# output paths
$outputLibrewolf = "$env:SystemDrive\$librewolfFileName"
if ($args -ne 'noupdater') { $outputLibrewolfUpdater = "$env:SystemDrive\librewolf-winupdater.zip" }
if ($NoUpdater) { $outputLibrewolfUpdater = "$env:SystemDrive\librewolf-winupdater.zip" }

Write-Warning "Downloading the latest LibreWolf setup"
& curl.exe -LSs "$librewolfDownload" -o "$outputLibrewolf"
if ($args -ne 'noupdater') {
if ($NoUpdater) {
Write-Warning "Downloading the latest LibreWolf WinUpdater ZIP"
& curl.exe -LSs "$librewolfUpdaterDownload" -o "$outputLibrewolfUpdater"
}
Expand All @@ -42,12 +46,12 @@ if (!(Test-Path $librewolfPath)) {
Write-Host "Installing LibreWolf silently failed."
exit 1
}
if ($args -ne 'noupdater') {
if ($NoUpdater) {
Write-Warning "Installing/extracting Librewolf-WinUpdater"
Expand-Archive -Path $outputLibrewolfUpdater -DestinationPath "$env:ProgramFiles\LibreWolf\librewolf-winupdater" -Force
}

if ($args -ne 'noupdater') {
if ($NoUpdater) {
Write-Warning "Adding automatic updater task"
$Title = "LibreWolf WinUpdater"
$Action = New-ScheduledTaskAction -Execute "$updaterPath\LibreWolf-WinUpdater.exe" -Argument "/Scheduled"
Expand All @@ -69,8 +73,8 @@ function Create-Shortcut {
$Shortcut.Save()
}
Create-Shortcut -Source "$librewolfPath\librewolf.exe" -Destination "$desktop\LibreWolf.lnk" -WorkingDir $librewolfPath
if ($args -ne 'noupdater') { Create-Shortcut -Source "$updaterPath\Librewolf-WinUpdater.exe" -Destination "$startMenu\LibreWolf\LibreWolf WinUpdater.lnk" -WorkingDir $librewolfPath }
if ($NoUpdater) { Create-Shortcut -Source "$updaterPath\Librewolf-WinUpdater.exe" -Destination "$startMenu\LibreWolf\LibreWolf WinUpdater.lnk" -WorkingDir $librewolfPath }

Write-Warning "Removing temporary installer files"
Remove-Item "$outputLibrewolf" -Force
if ($args -ne 'noupdater') { Remove-Item "$outputLibrewolfUpdater" -Force }
if ($NoUpdater) { Remove-Item "$outputLibrewolfUpdater" -Force }

0 comments on commit 5b655d5

Please sign in to comment.