kms-website: fix consent prompt suppressed by KMS_AUTO

The activate-windows/office wrappers set $env:KMS_AUTO to pre-select the
product, but Approve() treated any KMS_AUTO as "non-interactive" and skipped the
consequences prompt -- so on a machine needing the ODT/edition install it printed
the consequences then exited without asking. Gate the prompt on a real console
([Environment]::UserInteractive + not IsInputRedirected, guarded) instead of
KMS_AUTO. KMS_AUTO now only selects WHICH products to activate.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Viktor Barzin 2026-06-01 19:23:51 +00:00
parent d3c52b3bf7
commit 06009dae30

View file

@ -64,15 +64,18 @@ function Choice([string]$key, [string]$prompt, [bool]$default) {
}
# Show the consequences of a destructive/heavy action and get consent (default No).
# Interactive -> prompt. Non-interactive (KMS_AUTO set or no console) -> proceed
# ONLY if an explicit env override gave consent ($envConsent), else skip.
# Gate ONLY on whether there's a real console. NB: $env:KMS_AUTO just pre-selects
# WHICH products to activate (so the activate-windows/office one-liners can set it)
# -- it must NOT suppress this prompt. With a console -> prompt; headless -> proceed
# only if an explicit env override gave consent, else skip.
function Approve([string]$consequences, [bool]$envConsent) {
Write-Host ""
Write-Host $consequences -ForegroundColor Yellow
$interactive = ($auto.Count -eq 0) -and [Environment]::UserInteractive
if ($interactive) { return (Ask "Proceed?" $false) }
if ($envConsent) { Write-Host " (non-interactive; proceeding on explicit env override)"; return $true }
Warn "Skipped (non-interactive and no explicit env override to consent)."
$canPrompt = $false
try { $canPrompt = [Environment]::UserInteractive -and -not [Console]::IsInputRedirected } catch { $canPrompt = $false }
if ($canPrompt) { return (Ask "Proceed?" $false) }
if ($envConsent) { Write-Host " (non-interactive; proceeding on explicit env override)"; return $true }
Warn "Skipped: this needs confirmation. Re-run in an interactive PowerShell window, or set the override env var (e.g. `$env:KMS_OFFICE_PRODUCT or `$env:KMS_EDITION) to consent non-interactively."
return $false
}