Add native Windows PowerShell installer script (install.ps1)

- Add scripts/install.ps1 for native Windows (PowerShell) one-line bootstrap (irm ... | iex) without requiring WSL2, Node.js, or Bun.
- Support candidate mirror failover (Gitea primary, GitHub fallback), SHA-256 checksum verification, non-admin User PATH configuration, and automatic Agent Skill initialization.
- Update README.md, skills/seal-use/SKILL.md, and scripts/README.md to document the Windows one-liner installation.
This commit is contained in:
gitea committed 2026-11-17 15:44:33 +08:00
1 parent e88f472b50
commit 09c72d998a
4 files changed
+337 -5

No files matched your search

+3 -2
View File
@@ -20,7 +20,8 @@ scripts/
├── bump-version.ts # 多清单版本原子同步(package.json / plugin.json / SKILL.md 等)
├── release.ts # 受控保护分支发布流水线(严格遵循 merge-before-tag)
├── dev-override.ts # 本地开发二进制编译与全局 PATH 覆盖测试
├── install.sh # 生产级免 sudo 快速安装 Shell 脚本(公开 cURL 入口,不可移动)
├── install.sh # 生产级免 sudo 快速安装 Shell 脚本(macOS / Linux 公开 cURL 入口,不可移动)
├── install.ps1 # 生产级免管理员提权快速安装 PowerShell 脚本(Windows 原生公开 irm 入口)
│
├── generate-cli-md.mjs # 从 CLI 注册表自动生成 references/cli.md
├── check-cli-md.mjs # CLI 文档防漂移校验
@@ -36,6 +37,6 @@ scripts/
1. **绝对隔离**:`src/` 业务代码不可依赖 `scripts/`。`scripts/` 是外部工具,不是领域服务。
2. **高危受限脚本**:
- `release.ts` 与 `bump-version.ts` 具有强版本与 Git 标签推进副作用,**必须且仅能在人类明确发出发布指令时**通过 `bun run release` 调度,任何 Agent 不得擅自调用。
- `install.sh` 是被公开文档直接通过 `curl .../scripts/install.sh | bash` 引用的外部入口,路径不可擅改。
- `install.sh` 与 `install.ps1` 是被公开文档直接通过 `curl .../install.sh | bash` 与 `irm .../install.ps1 | iex` 引用的外部安装入口,路径不可擅改。
3. **治理优先**:
- 日常执行 `bun test` 会自动回归 `scripts/governance/*.test.ts`,确保治理规则与真实文件不漂移。
+310
View File
@@ -0,0 +1,310 @@
# scripts/install.ps1 - Native Windows PowerShell installer for seal-use CLI.
# Usage:
# irm https://git.ying-qing.cn/gitea/seal-use/raw/branch/main/scripts/install.ps1 | iex
# Or with parameters:
# & ([scriptblock]::Create((irm ...))) -Version 0.11.22
[CmdletBinding()]
param(
[string]$Version = "",
[string]$InstallDir = ""
)
$ErrorActionPreference = "Stop"
# Enable modern TLS protocols on older PowerShell 5.1 hosts
try {
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
} catch {
# Ignore if TLS12 is already default or unsupported
}
Write-Host "==> Detecting Windows platform and architecture..." -ForegroundColor Cyan
if (-not [System.Environment]::Is64BitOperatingSystem) {
Write-Error "seal-use requires a 64-bit Windows operating system (x64)."
exit 1
}
$ARCH_NAME = "x64"
$PLATFORM = "windows"
$REPO = if ($env:SEAL_USE_GITHUB_REPO) { $env:SEAL_USE_GITHUB_REPO }
elseif ($env:SEAL_HOME_GITHUB_REPO) { $env:SEAL_HOME_GITHUB_REPO }
else { "yunyingk/seal-use" }
$REQ_VERSION = if ($Version) { $Version }
elseif ($env:SEAL_USE_VERSION) { $env:SEAL_USE_VERSION }
elseif ($env:SEAL_HOME_VERSION) { $env:SEAL_HOME_VERSION }
else { "latest" }
if ($REQ_VERSION -ne "latest" -and -not $REQ_VERSION.StartsWith("v")) {
$REQ_VERSION = "v$REQ_VERSION"
}
# Resolve target directory without requiring administrator privileges
$TARGET_DIR = if ($InstallDir) { $InstallDir }
elseif ($env:SEAL_USE_INSTALL_DIR) { $env:SEAL_USE_INSTALL_DIR }
elseif ($env:SEAL_HOME_INSTALL_DIR) { $env:SEAL_HOME_INSTALL_DIR }
else { "" }
if (-not $TARGET_DIR) {
$existing = Get-Command "seal-use" -ErrorAction SilentlyContinue
if ($existing -and $existing.Source -and (Test-Path $existing.Source)) {
$existingDir = Split-Path -Parent $existing.Source
if ($existingDir -notlike "*WindowsApps*" -and (Test-Path $existingDir)) {
$TARGET_DIR = $existingDir
}
}
}
if (-not $TARGET_DIR) {
$TARGET_DIR = Join-Path $HOME ".local\bin"
}
if (-not (Test-Path $TARGET_DIR)) {
New-Item -ItemType Directory -Path $TARGET_DIR -Force | Out-Null
}
$ASSET_NAME = "seal-use-$PLATFORM-$ARCH_NAME.exe"
$ARCHIVE_NAME = "seal-use-$PLATFORM-$ARCH_NAME.zip"
$TARGET_PATH = Join-Path $TARGET_DIR "seal-use.exe"
function Format-Bytes([long]$bytes) {
if ($bytes -ge 1048576) {
return ("{0:N2} MB ({1:N0} bytes)" -f ($bytes / 1MB), $bytes)
} elseif ($bytes -ge 1024) {
return ("{0:N2} KB ({1:N0} bytes)" -f ($bytes / 1KB), $bytes)
} else {
return ("{0} bytes" -f $bytes)
}
}
function Extract-Host([string]$url) {
try {
$uri = [System.Uri]$url
return $uri.Host
} catch {
return $url
}
}
$GITEA_TAG = if ($REQ_VERSION -eq "latest") { "latest" } else { $REQ_VERSION }
$GH_RELEASE_PATH = if ($REQ_VERSION -eq "latest") { "latest/download" } else { $REQ_VERSION }
$MIRROR_MODE = if ($env:SEAL_USE_MIRROR) { $env:SEAL_USE_MIRROR }
elseif ($env:SEAL_HOME_MIRROR) { $env:SEAL_HOME_MIRROR }
else { "auto" }
function Get-CandidateUrls([string]$asset) {
$urls = [System.Collections.Generic.List[string]]::new()
if ($MIRROR_MODE -ne "github") {
$urls.Add("https://git.ying-qing.cn/gitea/seal-use/releases/download/$GITEA_TAG/$asset")
$urls.Add("https://git.ying-qing.cn/gitea/seal-home/releases/download/$GITEA_TAG/$asset")
}
if ($MIRROR_MODE -ne "gitea") {
$urls.Add("https://github.com/$REPO/releases/download/$GH_RELEASE_PATH/$asset")
$urls.Add("https://ghfast.top/https://github.com/$REPO/releases/download/$GH_RELEASE_PATH/$asset")
}
return $urls
}
function Download-Candidate([string]$url, [string]$dest) {
$hostName = Extract-Host $url
Write-Host "==> Downloading from $hostName" -ForegroundColor Cyan
Write-Host " Source Host: $hostName"
Write-Host " Source URL: $url"
try {
# Test headers and download using Invoke-WebRequest with basic parsing
Invoke-WebRequest -Uri $url -OutFile $dest -UseBasicParsing -TimeoutSec 45 -ErrorAction Stop
if (Test-Path $dest) {
$item = Get-Item $dest
if ($item.Length -gt 1000000) {
Write-Host "✓ Download complete! Total size: $(Format-Bytes $item.Length)" -ForegroundColor Green
Write-Host "✓ Successfully fetched from host: $hostName" -ForegroundColor Green
return $true
}
}
} catch {
Write-Host " ↳ Source unreachable or asset not ready ($($_.Exception.Message)), falling back to next mirror..." -ForegroundColor Yellow
}
if (Test-Path $dest) {
Remove-Item -Path $dest -Force -ErrorAction SilentlyContinue
}
return $false
}
function Verify-Checksum([string]$filePath, [string]$assetName) {
$checksumUrls = [System.Collections.Generic.List[string]]::new()
if ($MIRROR_MODE -ne "github") {
$checksumUrls.Add("https://git.ying-qing.cn/gitea/seal-use/releases/download/$GITEA_TAG/checksums.txt")
$checksumUrls.Add("https://git.ying-qing.cn/gitea/seal-home/releases/download/$GITEA_TAG/checksums.txt")
}
if ($MIRROR_MODE -ne "gitea") {
$checksumUrls.Add("https://github.com/$REPO/releases/download/$GH_RELEASE_PATH/checksums.txt")
$checksumUrls.Add("https://ghfast.top/https://github.com/$REPO/releases/download/$GH_RELEASE_PATH/checksums.txt")
}
$tmpSum = [System.IO.Path]::GetTempFileName()
$checksumFound = $false
foreach ($cUrl in $checksumUrls) {
try {
Invoke-WebRequest -Uri $cUrl -OutFile $tmpSum -UseBasicParsing -TimeoutSec 15 -ErrorAction Stop
if (Test-Path $tmpSum) {
$checksumFound = $true
break
}
} catch {
continue
}
}
if ($checksumFound) {
try {
$lines = Get-Content -Path $tmpSum -ErrorAction SilentlyContinue
$expectedHash = ""
foreach ($line in $lines) {
$parts = -split $line.Trim()
if ($parts.Length -ge 2 -and $parts[1] -eq $assetName) {
$expectedHash = $parts[0]
break
}
}
if ($expectedHash) {
$actualHash = (Get-FileHash -Path $filePath -Algorithm SHA256).Hash.ToLowerInvariant()
if ($actualHash -eq $expectedHash.ToLowerInvariant()) {
Write-Host "✓ Checksum verification passed (SHA-256: $($actualHash.Substring(0, 12))...)" -ForegroundColor Green
} else {
Write-Warning "Checksum mismatch for $assetName! Expected: $expectedHash, got: $actualHash"
}
}
} finally {
Remove-Item -Path $tmpSum -Force -ErrorAction SilentlyContinue
}
}
}
Write-Host "==> Target install location: $TARGET_PATH"
Write-Host "==> Requested version: $REQ_VERSION"
$TMP_ZIP = Join-Path ([System.IO.Path]::GetTempPath()) ("seal-use-download-" + [System.Guid]::NewGuid().ToString("N") + ".zip")
$TMP_EXE = Join-Path ([System.IO.Path]::GetTempPath()) ("seal-use-download-" + [System.Guid]::NewGuid().ToString("N") + ".exe")
$TMP_FILE = ""
$DOWNLOAD_SUCCESS = $false
$IS_ARCHIVE = $false
$USED_ASSET = ""
# Prefer compressed archive (zip) over raw binary: smaller download (~44MB vs ~107MB)
foreach ($url in (Get-CandidateUrls $ARCHIVE_NAME)) {
if (Download-Candidate -url $url -dest $TMP_ZIP) {
$DOWNLOAD_SUCCESS = $true
$IS_ARCHIVE = $true
$USED_ASSET = $ARCHIVE_NAME
$TMP_FILE = $TMP_ZIP
break
}
}
if (-not $DOWNLOAD_SUCCESS) {
foreach ($url in (Get-CandidateUrls $ASSET_NAME)) {
if (Download-Candidate -url $url -dest $TMP_EXE) {
$DOWNLOAD_SUCCESS = $true
$IS_ARCHIVE = $false
$USED_ASSET = $ASSET_NAME
$TMP_FILE = $TMP_EXE
break
}
}
}
if (-not $DOWNLOAD_SUCCESS) {
Write-Error "Failed to download $ARCHIVE_NAME or $ASSET_NAME ($REQ_VERSION) from all candidate mirrors."
if (Test-Path $TMP_FILE) { Remove-Item -Path $TMP_FILE -Force -ErrorAction SilentlyContinue }
exit 1
}
Verify-Checksum -filePath $TMP_FILE -assetName $USED_ASSET
if ($IS_ARCHIVE) {
$EXTRACT_DIR = Join-Path ([System.IO.Path]::GetTempPath()) ("seal-use-extract-" + [System.Guid]::NewGuid().ToString("N"))
Write-Host "==> Extracting $USED_ASSET..." -ForegroundColor Cyan
try {
Expand-Archive -Path $TMP_FILE -DestinationPath $EXTRACT_DIR -Force
$extractedExe = Get-ChildItem -Path $EXTRACT_DIR -Filter "*seal-use*.exe" -Recurse | Select-Object -First 1
if (-not $extractedExe) {
Write-Error "$USED_ASSET did not contain a seal-use binary."
exit 1
}
# Handle locked running binary by moving old image first
if (Test-Path $TARGET_PATH) {
$oldPath = "$TARGET_PATH.old.$([DateTimeOffset]::UtcNow.ToUnixTimeSeconds())"
try {
Move-Item -Path $TARGET_PATH -Destination $oldPath -Force -ErrorAction SilentlyContinue
} catch {
# Ignore if file is not locked
}
}
Move-Item -Path $extractedExe.FullName -Destination $TARGET_PATH -Force
} finally {
Remove-Item -Path $EXTRACT_DIR -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path $TMP_FILE -Force -ErrorAction SilentlyContinue
}
} else {
if (Test-Path $TARGET_PATH) {
$oldPath = "$TARGET_PATH.old.$([DateTimeOffset]::UtcNow.ToUnixTimeSeconds())"
try {
Move-Item -Path $TARGET_PATH -Destination $oldPath -Force -ErrorAction SilentlyContinue
} catch {}
}
Move-Item -Path $TMP_FILE -Destination $TARGET_PATH -Force
}
# Ensure TARGET_DIR is in Windows User PATH environment variable
try {
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
$paths = ($userPath -split ';') | Where-Object { $_ -and $_.Trim() -ne "" }
if ($paths -notcontains $TARGET_DIR) {
$newUserPath = if ([string]::IsNullOrEmpty($userPath)) { $TARGET_DIR } else { "$userPath;$TARGET_DIR" }
[Environment]::SetEnvironmentVariable("Path", $newUserPath, "User")
Write-Host "==> Added $TARGET_DIR to User PATH environment variable." -ForegroundColor Cyan
}
} catch {
Write-Warning "Could not update User PATH environment variable automatically. Please add $TARGET_DIR to your PATH manually."
}
# Update current session environment PATH
$sessionPaths = ($env:Path -split ';') | Where-Object { $_ -and $_.Trim() -ne "" }
if ($sessionPaths -notcontains $TARGET_DIR) {
$env:Path = "$TARGET_DIR;$env:Path"
}
# Clean legacy skill to avoid model routing collisions
$LEGACY_SKILL_DIR = Join-Path $HOME ".agents\skills\seal-home"
if (Test-Path $LEGACY_SKILL_DIR) {
Write-Host "==> Removing legacy agent skill at $LEGACY_SKILL_DIR..." -ForegroundColor Cyan
Remove-Item -Path $LEGACY_SKILL_DIR -Recurse -Force -ErrorAction SilentlyContinue
}
# Initialize agent skill
Write-Host "==> Initializing agent skill to ~/.agents/skills/seal-use..." -ForegroundColor Cyan
try {
& $TARGET_PATH skill install 2>$null | Out-Null
Write-Host "✓ Agent skill installed to ~/.agents/skills/seal-use" -ForegroundColor Green
} catch {
Write-Warning "Could not initialize agent skill automatically. Run 'seal-use skill install' to complete."
}
Write-Host ""
Write-Host "✨ seal-use successfully installed to $TARGET_PATH!" -ForegroundColor Green
& $TARGET_PATH version
Write-Host ""
Write-Host "Quick start:"
Write-Host " 1. Add enterprise: seal-use corps add-hose-persistent --json '{...}'"
Write-Host " 2. View MCP config: seal-use mcp-config"
Write-Host " 3. Self-update: seal-use update"
Write-Host ""