support custom manifest
This commit is contained in:
52
bin/main.ps1
52
bin/main.ps1
@@ -54,6 +54,11 @@ if (Test-Path $selectionPath) {
|
||||
}
|
||||
}
|
||||
|
||||
# === 2.2 启用本地 Manifest 安装 ===
|
||||
# winget install --manifest 需要先启用 LocalManifestFiles,重复执行不会影响后续安装。
|
||||
Write-Host "Enabling winget local manifest support..." -ForegroundColor Cyan
|
||||
winget settings --enable LocalManifestFiles
|
||||
|
||||
# === 3. 主循环 ===
|
||||
foreach ($app in $apps) {
|
||||
if ($app.Enabled -ne 1) {
|
||||
@@ -70,6 +75,46 @@ foreach ($app in $apps) {
|
||||
Write-Host "[System Config] Skipping install..." -ForegroundColor Magenta
|
||||
} else {
|
||||
# --- 步骤 A: Winget 安装 ---
|
||||
$manifestPath = $null
|
||||
$manifestTempDir = $null
|
||||
|
||||
if (-not [string]::IsNullOrWhiteSpace($app.Manifest)) {
|
||||
Write-Host "-> Manifest: $($app.Manifest)"
|
||||
|
||||
if ($app.Manifest -match '^https?://') {
|
||||
$manifestTempDir = Join-Path $env:TEMP ("winit-helper-manifest-" + [guid]::NewGuid().ToString("N"))
|
||||
New-Item -ItemType Directory -Path $manifestTempDir -Force | Out-Null
|
||||
|
||||
$manifestFileName = [System.IO.Path]::GetFileName(([uri]$app.Manifest).AbsolutePath)
|
||||
if ([string]::IsNullOrWhiteSpace($manifestFileName)) {
|
||||
$manifestFileName = "$($app.Id).yaml"
|
||||
}
|
||||
|
||||
$manifestPath = Join-Path $manifestTempDir $manifestFileName
|
||||
Write-Host "-> Downloading custom manifest..."
|
||||
Invoke-WebRequest -Uri $app.Manifest -OutFile $manifestPath
|
||||
} else {
|
||||
$manifestPath = $app.Manifest
|
||||
if (-not [System.IO.Path]::IsPathRooted($manifestPath)) {
|
||||
$manifestPath = Join-Path $PSScriptRoot $manifestPath
|
||||
}
|
||||
|
||||
if (-not (Test-Path $manifestPath)) {
|
||||
Write-Error "Cannot find manifest: $manifestPath"
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
$wingetArgs = @(
|
||||
"install",
|
||||
"--manifest", $manifestPath,
|
||||
"--silent",
|
||||
"--accept-package-agreements",
|
||||
"--accept-source-agreements",
|
||||
"--disable-interactivity"
|
||||
# "--scope", "machine"
|
||||
)
|
||||
} else {
|
||||
$wingetArgs = @(
|
||||
"install",
|
||||
"--id", $app.Id,
|
||||
@@ -90,11 +135,18 @@ foreach ($app in $apps) {
|
||||
} else {
|
||||
Write-Host "-> Version: latest"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "-> Installing via winget..."
|
||||
|
||||
# 执行安装
|
||||
try {
|
||||
$proc = Start-Process -FilePath "winget" -ArgumentList $wingetArgs -Wait -PassThru -NoNewWindow
|
||||
} finally {
|
||||
if ($manifestTempDir -and (Test-Path $manifestTempDir)) {
|
||||
Remove-Item -LiteralPath $manifestTempDir -Recurse -Force
|
||||
}
|
||||
}
|
||||
|
||||
# 检查安装结果 (0=成功, -1978335189=已安装)
|
||||
if ($proc.ExitCode -eq 0) {
|
||||
|
||||
Reference in New Issue
Block a user