triton-install/manage-server/uninstall.ps1
amir-climy 5cb8ce2f63 feat(install): macOS + Windows support
install.sh / uninstall.sh (Linux + macOS):
- Detect OS with uname -s; root check is Linux-only (Docker/Podman Desktop
  on macOS runs rootless, no sudo needed).
- Arch detection adds arm64 case for Apple Silicon (uname -m returns "arm64"
  on macOS, "aarch64" on Linux).
- sed_inplace() wrapper handles BSD sed on macOS (requires empty -i suffix).
- Fix --image flag to append TRITON_MANAGE_IMAGE rather than sed-replace a
  line that is commented out in env.template.
- uninstall: re-apply --purge-data fixes (rm installer dir, drop interactive
  prompt, use $RUNTIME for raw cleanup instead of hardcoded podman).

install.ps1 / uninstall.ps1 (Windows):
- Equivalent logic for Docker Desktop / Podman Desktop on Windows.
- Arch via RuntimeInformation.OSArchitecture (X64 → amd64, Arm64 → arm64).
- Secrets via RandomNumberGenerator (no openssl dependency).
- Parameters: -GatewayHostname, -ManageHostIP, -Image, -NoTls / -PurgeData.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 15:07:13 +08:00

68 lines
3 KiB
PowerShell

#Requires -Version 5.1
# uninstall.ps1 — stop and remove Manage Server containers on Windows.
#
# By default, KEEPS the PostgreSQL volume (scan history, hosts, users)
# and the installer directory (preserves .env secrets for reinstall).
# Pass -PurgeData to delete volumes + installer directory — irreversible.
#
# Usage:
# .\uninstall.ps1 # stop + remove containers, keep DB + .env
# .\uninstall.ps1 -PurgeData # also delete DB, volumes, and installer dir
param(
[switch]$PurgeData
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $ScriptDir
function Write-Info([string]$msg) { Write-Host "[manage-server] $msg" }
function Write-Die([string]$msg) { Write-Error "[manage-server] error: $msg"; exit 1 }
# ── runtime detection ────────────────────────────────────────────────────
$composeCmd = $null
$runtime = $null
if (Get-Command docker -ErrorAction SilentlyContinue) {
& docker compose version 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) { $composeCmd = @('docker','compose'); $runtime = 'docker' }
}
if (-not $composeCmd -and (Get-Command podman -ErrorAction SilentlyContinue)) {
& podman compose version 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) { $composeCmd = @('podman','compose'); $runtime = 'podman' }
}
if (-not $composeCmd) { Write-Die "no compose runtime found" }
# ── stop containers ──────────────────────────────────────────────────────
$envFile = Join-Path $ScriptDir '.env'
if (Test-Path $envFile) {
Write-Info "stopping containers..."
& $composeCmd[0] $composeCmd[1] --env-file $envFile down
} else {
Write-Info ".env not found, attempting raw container cleanup..."
$ErrorActionPreference = 'Continue'
& $runtime rm -f triton-manageserver triton-manage-db 2>$null
$ErrorActionPreference = 'Stop'
}
# ── purge ────────────────────────────────────────────────────────────────
if ($PurgeData) {
Write-Info "DESTRUCTIVE: removing manage server volumes..."
Write-Info " this deletes: scan history, hosts, users, worker binaries"
$ErrorActionPreference = 'Continue'
foreach ($vol in @('triton-manage-db-data', 'triton-manage-bins')) {
& $runtime volume rm -f $vol 2>$null
}
$ErrorActionPreference = 'Stop'
Write-Info " volumes removed"
Write-Info " removing installer directory $ScriptDir..."
Remove-Item -Recurse -Force $ScriptDir
Write-Info " installer directory removed"
} else {
Write-Info "DB + bins volumes retained (run with -PurgeData to delete)"
Write-Info ".env preserved at $envFile — secrets reused on reinstall"
}
Write-Info "uninstall complete"