Skip to content

Commit

Permalink
feat: replace WinGet with script
Browse files Browse the repository at this point in the history
it's more reliable and faster this way
  • Loading branch information
he3als committed Sep 28, 2023
1 parent a73c3e5 commit c14e255
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 160 deletions.
37 changes: 14 additions & 23 deletions src/playbook/Configuration/atlas/start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,51 +44,42 @@ actions:

- !writeStatus: {status: 'Installing software'}
- !run:
exe: 'NSudoLC.exe'
args: '-U:E -UseCurrentConsole -Wait powershell.exe -NoP -File "WINGET.ps1"'
exe: 'powershell.exe'
args: '-NoP -File "SOFTWARE.ps1"'
wait: true
exeDir: true
weight: 150
- !writeStatus: {status: 'Installing Google Chrome', option: 'browser-chrome'}
- !run:
exe: 'NSudoLC.exe'
args: '-U:E -UseCurrentConsole -Wait powershell.exe -NoP -File "WINGET.ps1" LibreWolf.LibreWolf'
exe: 'powershell.exe'
args: '-NoP -File "SOFTWARE.ps1" -Chrome'
wait: true
exeDir: true
weight: 150
option: 'librewolf-winget'
option: 'browser-chrome'
- !writeStatus: {status: 'Installing Brave', option: 'browser-brave'}
- !run:
exe: 'NSudoLC.exe'
args: '-U:E -UseCurrentConsole -Wait powershell.exe -NoP -File "WINGET.ps1" Google.Chrome'
exe: 'powershell.exe'
args: '-NoP -File "SOFTWARE.ps1" -Brave'
wait: true
exeDir: true
weight: 150
option: 'browser-chrome'
################
## Non-WinGet ##
################
option: 'browser-brave'

- !writeStatus: {status: 'Installing LibreWolf', option: 'browser-librewolf'}
- !run:
exe: 'powershell.exe'
args: '-NoP -File LIBREWOLF.ps1'
exeDir: true
wait: true
weight: 150
option: 'librewolf-winupdater'
# Can't be installed system-wide with Chocolatey or other package managers
# https://github.com/brave/brave-browser/issues/25571
- !run:
exe: 'powershell.exe'
args: '-NoP -File BRAVE.ps1'
args: '-NoP -File "LIBREWOLF.ps1" noupdater'
exeDir: true
wait: true
weight: 150
option: 'browser-brave'
- !taskKill {name: 'brave', option: 'browser-brave'}
option: 'librewolf-winget'

################ END NO LOCAL BUILD ################

# Should be cleaned up by cleanmgr, fails most of the time anyways

# - !file:
# path: '%windir%\SoftwareDistribution'
# weight: 20
# ignoreErrors: true
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ exit /b %errorlevel%
: end batch / begin PowerShell #>

param (
[switch]$Enable,
[switch]$Disable,
[switch]$SafeMode,
[switch]$Enable,
[switch]$Disable,
[switch]$SafeMode,
[switch]$DisableFailedMessage
)

Expand Down
20 changes: 0 additions & 20 deletions src/playbook/Executables/BRAVE.ps1

This file was deleted.

53 changes: 30 additions & 23 deletions src/playbook/Executables/LIBREWOLF.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $ProgressPreference = "SilentlyContinue"
# stop on errors, as each command is vital
$ErrorActionPreference = "Stop"

$updaterPath = "$env:ProgramFiles\LibreWolf\librewolf-winupdater"
if ($args -ne '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,39 +18,46 @@ 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"
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 |
Where-Object { $_.name -like "*.zip" } |
Select-Object -ExpandProperty browser_download_url

if ($args -ne '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 |
Where-Object { $_.name -like "*.zip" } |
Select-Object -ExpandProperty browser_download_url
}
# output paths
$outputLibrewolf = "$env:SystemDrive\$librewolfFileName"
$outputLibrewolfUpdater = "$env:SystemDrive\librewolf-winupdater.zip"
if ($args -ne 'noupdater') { $outputLibrewolfUpdater = "$env:SystemDrive\librewolf-winupdater.zip" }

Write-Warning "Downloading the latest LibreWolf setup"
Invoke-WebRequest -Uri $librewolfDownload -OutFile $outputLibrewolf
Write-Warning "Downloading the latest LibreWolf WinUpdater ZIP"
Invoke-WebRequest -Uri $librewolfUpdaterDownload -OutFile $outputLibrewolfUpdater
if ($args -ne 'noupdater') {
Write-Warning "Downloading the latest LibreWolf WinUpdater ZIP"
Invoke-WebRequest -Uri $librewolfUpdaterDownload -OutFile $outputLibrewolfUpdater
}

Write-Warning "Installing LibreWolf silently"
Start-Process -Wait -FilePath $outputLibrewolf -ArgumentList "/S"
if (!(Test-Path $librewolfPath)) {
Write-Host "Installing LibreWolf silently failed."
exit 1
}
Write-Warning "Installing/extracting Librewolf-WinUpdater"
Expand-Archive -Path $outputLibrewolfUpdater -DestinationPath "$env:ProgramFiles\LibreWolf\librewolf-winupdater" -Force
if ($args -ne 'noupdater') {
Write-Warning "Installing/extracting Librewolf-WinUpdater"
Expand-Archive -Path $outputLibrewolfUpdater -DestinationPath "$env:ProgramFiles\LibreWolf\librewolf-winupdater" -Force
}

Write-Warning "Adding automatic updater task"
$Title = "LibreWolf WinUpdater"
$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 = (Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -ExpandProperty UserName) -replace ".*\\"
Register-ScheduledTask -TaskName "$Title ($User)" -Action $Action -Settings $Settings -Trigger $7Hours,$AtLogon -User $User -RunLevel Highest -Force | Out-Null
if ($args -ne 'noupdater') {
Write-Warning "Adding automatic updater task"
$Title = "LibreWolf WinUpdater"
$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 = (Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -ExpandProperty UserName) -replace ".*\\"
Register-ScheduledTask -TaskName "$Title ($User)" -Action $Action -Settings $Settings -Trigger $7Hours,$AtLogon -User $User -RunLevel Highest -Force | Out-Null
}

Write-Warning "Creating shortcuts"
function Create-Shortcut {
Expand All @@ -62,8 +69,8 @@ function Create-Shortcut {
$Shortcut.Save()
}
Create-Shortcut -Source "$librewolfPath\librewolf.exe" -Destination "$desktop\LibreWolf.lnk" -WorkingDir $librewolfPath
Create-Shortcut -Source "$updaterPath\Librewolf-WinUpdater.exe" -Destination "$startMenu\LibreWolf\LibreWolf WinUpdater.lnk" -WorkingDir $librewolfPath
if ($args -ne '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
Remove-Item "$outputLibrewolfUpdater" -Force
if ($args -ne 'noupdater') { Remove-Item "$outputLibrewolfUpdater" -Force }
96 changes: 96 additions & 0 deletions src/playbook/Executables/SOFTWARE.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
param (
[switch]$Chrome,
[switch]$Brave
)

# ----------------------------------------------------------------------------------------------------------- #
# Software is no longer installed with a package manager anymore to be as fast and as reliable as possible. #
# ----------------------------------------------------------------------------------------------------------- #

# Create temporary directory
$tempDir = Join-Path -Path $env:TEMP -ChildPath $([System.IO.Path]::GetRandomFileName())
New-Item $tempDir -ItemType Directory -Force | Out-Null
Set-Location $tempDir

# Chrome
if ($Chrome) {
Write-Host "Installing Google Chrome..."
& curl.exe -LSs "https://dl.google.com/dl/chrome/install/googlechromestandaloneenterprise64.msi" -o "$tempDir\chrome.msi"
Start-Process -FilePath "$tempDir\chrome.msi" -WindowStyle Hidden -ArgumentList '/qn' -Wait
exit
}

# Brave
if ($Brave) {
Write-Host "Installing Brave..."
& curl.exe -LSs "https://laptop-updates.brave.com/latest/winx64" -o "$tempDir\BraveSetup.exe"
if (!$?) {
Write-Error "Downloading Brave failed."
exit 1
}

& "$tempDir\BraveSetup.exe" /silent /install

do {
$processesFound = Get-Process | Where-Object { "BraveSetup" -contains $_.Name } | Select-Object -ExpandProperty Name
if ($processesFound) {
Write-Host "Still running BraveSetup."
Start-Sleep -Seconds 2
} else {
Remove-Item "$tempDir" -ErrorAction SilentlyContinue -Force -Recurse
}
} until (!$processesFound)

Stop-Process -Name "brave" -Force -ErrorAction SilentlyContinue
exit
}

####################
## Software ##
####################

# Visual C++ Runtimes (referred to as vcredists for short)
# https://learn.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist
$legacyArgs1 = '/q'
$legacyArgs2 = '/q /norestart'
$modernArgs = "/install /quiet /norestart"

$vcredists = @{
# 2005
"https://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x64.EXE" = $legacyArgs1
# 2008
"https://download.microsoft.com/download/5/D/8/5D8C65CB-C849-4025-8E95-C3966CAFD8AE/vcredist_x64.exe" = $legacyArgs1
# 2010
"https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe" = $legacyArgs2
# 2012
"https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe" = $modernArgs
# 2013
"https://aka.ms/highdpimfc2013x64enu" = $modernArgs
# 2015+
"https://aka.ms/vs/17/release/vc_redist.x64.exe" = $modernArgs
}

$num = 0; foreach ($a in $vcredists.GetEnumerator()) {
$num++; $vcredist = "$tempDir\vcredist$num.exe"
# curl is faster than Invoke-WebRequest
Write-Host "Installing Visual C++ Runtime $num..."
& curl.exe -LSs "$($a.Name)" -o "$vcredist"
Start-Process -FilePath $vcredist -WindowStyle Hidden -ArgumentList $a.Value -Wait
}

# 7-Zip
if ($env:PROCESSOR_ARCHITECTURE -eq 'amd64') {$arch = 'x64'} else {$arch = 'arm64'}
$website = 'https://7-zip.org/'
$download = $website + ((Invoke-WebRequest $website -UseBasicParsing).Links.href | Where-Object { $_ -like "a/7z2301-$arch.exe" })
& curl.exe -LSs $download -o "$tempDir\7zip.exe"
Start-Process -FilePath "$tempDir\7zip.exe" -WindowStyle Hidden -ArgumentList '/S' -Wait

# 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"
Write-Host "Extracting legacy DirectX runtimes..."
Start-Process -FilePath "$tempDir\directx.exe" -WindowStyle Hidden -ArgumentList "/q /c /t:`"$tempDir\directx`"" -Wait
Write-Host "Installing legacy DirectX runtimes..."
Start-Process -FilePath "$tempDir\directx\dxsetup.exe" -WindowStyle Hidden -ArgumentList '/silent' -Wait

# Remove temporary directory
Remove-Item -Path $tempDir -Force -Recurse *>$null
91 changes: 0 additions & 91 deletions src/playbook/Executables/WINGET.ps1

This file was deleted.

0 comments on commit c14e255

Please sign in to comment.