From 562f394137dcaa228556273be900ddad54e58d67 Mon Sep 17 00:00:00 2001 From: X9 Dev Date: Tue, 21 Apr 2026 09:20:29 +0200 Subject: [PATCH] fix(software): pass winget exe path into background jobs, add exit 3010 as OK Background jobs do not reliably inherit PATH from the parent session, causing winget calls to fail silently. Now the resolved executable path is passed explicitly as an argument into each Start-Job scriptblock. Also treats exit code 3010 (success + reboot required) as OK. Co-Authored-By: Claude Sonnet 4.6 --- scripts/02-software.ps1 | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/02-software.ps1 b/scripts/02-software.ps1 index b8b942f..216493d 100644 --- a/scripts/02-software.ps1 +++ b/scripts/02-software.ps1 @@ -31,8 +31,11 @@ $Config = Load-Config $ConfigPath # ----------------------------------------------------------------------- Write-Log "Checking winget availability" -Level INFO -$winget = Get-Command winget -ErrorAction SilentlyContinue -if (-not $winget) { +$wingetExe = $null +$wingetCmd = Get-Command winget -ErrorAction SilentlyContinue +if ($wingetCmd) { + $wingetExe = $wingetCmd.Source +} else { # Try to find winget in known locations $wingetPaths = @( "$env:LOCALAPPDATA\Microsoft\WindowsApps\winget.exe" @@ -40,19 +43,19 @@ if (-not $winget) { ) foreach ($p in $wingetPaths) { $found = Get-Item $p -ErrorAction SilentlyContinue | Select-Object -First 1 - if ($found) { $winget = $found.FullName; break } + if ($found) { $wingetExe = $found.FullName; break } } } -if (-not $winget) { +if (-not $wingetExe) { Write-Log "winget not found - software installation skipped" -Level ERROR exit 1 } -Write-Log "winget found: $($winget.Source -or $winget)" -Level OK +Write-Log "winget found: $wingetExe" -Level OK # Accept agreements upfront -& winget source update --accept-source-agreements 2>&1 | Out-Null +& $wingetExe source update --accept-source-agreements 2>&1 | Out-Null # ----------------------------------------------------------------------- # Install packages from config @@ -68,9 +71,9 @@ if (Get-Feature $Config "software" "wingetInstalls") { $jobs = @() foreach ($pkg in $packages) { Write-Log " Starting: $($pkg.name) ($($pkg.wingetId))" -Level INFO - $jobs += Start-Job -ArgumentList $pkg.wingetId, $pkg.name -ScriptBlock { - param($wingetId, $name) - $output = & winget install --id $wingetId ` + $jobs += Start-Job -ArgumentList $pkg.wingetId, $pkg.name, $wingetExe -ScriptBlock { + param($wingetId, $name, $wingetExe) + $output = & $wingetExe install --id $wingetId ` --silent ` --accept-package-agreements ` --accept-source-agreements ` @@ -91,7 +94,7 @@ if (Get-Feature $Config "software" "wingetInstalls") { foreach ($job in $jobs) { $r = Receive-Job -Job $job - if ($r.ExitCode -eq 0) { + if ($r.ExitCode -eq 0 -or $r.ExitCode -eq 3010) { Write-Log " Installed OK: $($r.Name)" -Level OK } elseif ($r.ExitCode -eq -1978335189) { Write-Log " Already installed: $($r.Name)" -Level OK