support custom manifest
This commit is contained in:
88
bin/main.ps1
88
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. 主循环 ===
|
# === 3. 主循环 ===
|
||||||
foreach ($app in $apps) {
|
foreach ($app in $apps) {
|
||||||
if ($app.Enabled -ne 1) {
|
if ($app.Enabled -ne 1) {
|
||||||
@@ -70,31 +75,78 @@ foreach ($app in $apps) {
|
|||||||
Write-Host "[System Config] Skipping install..." -ForegroundColor Magenta
|
Write-Host "[System Config] Skipping install..." -ForegroundColor Magenta
|
||||||
} else {
|
} else {
|
||||||
# --- 步骤 A: Winget 安装 ---
|
# --- 步骤 A: Winget 安装 ---
|
||||||
$wingetArgs = @(
|
$manifestPath = $null
|
||||||
"install",
|
$manifestTempDir = $null
|
||||||
"--id", $app.Id,
|
|
||||||
"-e",
|
|
||||||
"--silent",
|
|
||||||
"--accept-package-agreements",
|
|
||||||
"--accept-source-agreements",
|
|
||||||
"--disable-interactivity"
|
|
||||||
# "--scope", "machine"
|
|
||||||
)
|
|
||||||
|
|
||||||
# [版本检查逻辑]
|
if (-not [string]::IsNullOrWhiteSpace($app.Manifest)) {
|
||||||
# 检查 Version 是否存在且不为空字符串
|
Write-Host "-> Manifest: $($app.Manifest)"
|
||||||
if (-not [string]::IsNullOrWhiteSpace($app.Version)) {
|
|
||||||
Write-Host "-> Version: $($app.Version)"
|
if ($app.Manifest -match '^https?://') {
|
||||||
$wingetArgs += "-v"
|
$manifestTempDir = Join-Path $env:TEMP ("winit-helper-manifest-" + [guid]::NewGuid().ToString("N"))
|
||||||
$wingetArgs += $app.Version
|
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 {
|
} else {
|
||||||
Write-Host "-> Version: latest"
|
$wingetArgs = @(
|
||||||
|
"install",
|
||||||
|
"--id", $app.Id,
|
||||||
|
"-e",
|
||||||
|
"--silent",
|
||||||
|
"--accept-package-agreements",
|
||||||
|
"--accept-source-agreements",
|
||||||
|
"--disable-interactivity"
|
||||||
|
# "--scope", "machine"
|
||||||
|
)
|
||||||
|
|
||||||
|
# [版本检查逻辑]
|
||||||
|
# 检查 Version 是否存在且不为空字符串
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($app.Version)) {
|
||||||
|
Write-Host "-> Version: $($app.Version)"
|
||||||
|
$wingetArgs += "-v"
|
||||||
|
$wingetArgs += $app.Version
|
||||||
|
} else {
|
||||||
|
Write-Host "-> Version: latest"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "-> Installing via winget..."
|
Write-Host "-> Installing via winget..."
|
||||||
|
|
||||||
# 执行安装
|
# 执行安装
|
||||||
$proc = Start-Process -FilePath "winget" -ArgumentList $wingetArgs -Wait -PassThru -NoNewWindow
|
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=已安装)
|
# 检查安装结果 (0=成功, -1978335189=已安装)
|
||||||
if ($proc.ExitCode -eq 0) {
|
if ($proc.ExitCode -eq 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user