windows/bootstrap: repair empty winget source before install
0x8a15000f ("Data required by the source is missing") aborts Git.Git /
GoLang.Go install on a virgin DesktopAppInstaller cache, then iex dies
on missing git. Reset+update the source once, pin --source winget, retry
without the pin, then fail loudly if the index is still empty.
This commit is contained in:
+50
-3
@@ -11,14 +11,61 @@ $Dest = Join-Path $env:LOCALAPPDATA 'rclone-dropbox-bisync'
|
||||
$Dropbox = 'D:\Dropbox'
|
||||
$Workdir = 'D:\rclone-bisync'
|
||||
|
||||
function Refresh-Path {
|
||||
$env:Path = [Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' +
|
||||
[Environment]::GetEnvironmentVariable('Path', 'User')
|
||||
}
|
||||
|
||||
# 0x8a15000f: winget source index missing/corrupt (common on a fresh DesktopAppInstaller).
|
||||
function Repair-WingetSource {
|
||||
if ($script:WingetSourceRepaired) { return }
|
||||
$winget = Get-Command winget -ErrorAction SilentlyContinue
|
||||
if (-not $winget) { return }
|
||||
$prev = $ErrorActionPreference
|
||||
$ErrorActionPreference = 'Continue'
|
||||
try {
|
||||
& winget source reset --force --disable-interactivity 2>&1 | Out-Null
|
||||
& winget source update --disable-interactivity 2>&1 | Out-Null
|
||||
} finally {
|
||||
$ErrorActionPreference = $prev
|
||||
}
|
||||
$script:WingetSourceRepaired = $true
|
||||
}
|
||||
|
||||
function Install-WithWinget($WingetId) {
|
||||
Repair-WingetSource
|
||||
$wingetArgs = @(
|
||||
'install', '-e', '--id', $WingetId,
|
||||
'--accept-package-agreements', '--accept-source-agreements',
|
||||
'--disable-interactivity', '--source', 'winget'
|
||||
)
|
||||
$prev = $ErrorActionPreference
|
||||
$ErrorActionPreference = 'Continue'
|
||||
try {
|
||||
& winget @wingetArgs
|
||||
if ($LASTEXITCODE -eq 0) { return }
|
||||
# Index still empty: reset once more, then retry without pinning the source
|
||||
# (some hosts only have msstore until cdn.winget.microsoft.com is reachable).
|
||||
& winget source reset --force --disable-interactivity 2>&1 | Out-Null
|
||||
& winget source update --disable-interactivity 2>&1 | Out-Null
|
||||
& winget install -e --id $WingetId --accept-package-agreements --accept-source-agreements --disable-interactivity
|
||||
if ($LASTEXITCODE -eq 0) { return }
|
||||
} finally {
|
||||
$ErrorActionPreference = $prev
|
||||
}
|
||||
throw "winget failed to install $WingetId (exit $LASTEXITCODE / 0x8a15000f = empty source cache). Run: winget source reset --force; winget source update"
|
||||
}
|
||||
|
||||
function Ensure-Cmd($Name, $WingetId) {
|
||||
if (Get-Command $Name -ErrorAction SilentlyContinue) { return }
|
||||
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
|
||||
throw "Need $Name on PATH (or winget to install $WingetId)"
|
||||
}
|
||||
winget install -e --id $WingetId --accept-package-agreements --accept-source-agreements
|
||||
$env:Path = [Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' +
|
||||
[Environment]::GetEnvironmentVariable('Path', 'User')
|
||||
Install-WithWinget $WingetId
|
||||
Refresh-Path
|
||||
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
|
||||
throw "$Name still missing after winget install $WingetId; open a new PowerShell and retry"
|
||||
}
|
||||
}
|
||||
|
||||
Ensure-Cmd git Git.Git
|
||||
|
||||
Reference in New Issue
Block a user