# 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 ""