fix(scripts): setup.ps1/sh comment parsing, network creation, elevation UX
- Strip inline comments from hosts template before hostname extraction - Create stellaops bridge network if missing (was only creating frontdoor) - Clear elevation warning with missing count, re-run instructions, clipboard copy - Both setup.ps1 (Windows) and setup.sh (Linux/macOS) fixed Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -410,9 +410,13 @@ function Test-HostsFile {
|
||||
}
|
||||
|
||||
$content = Get-Content $hostsPath -Raw
|
||||
$sourceLines = Get-Content $hostsSource | Where-Object {
|
||||
$sourceLines = Get-Content $hostsSource | ForEach-Object {
|
||||
$trimmed = $_.Trim()
|
||||
$trimmed -and -not $trimmed.StartsWith('#')
|
||||
# Skip blank lines and full-line comments
|
||||
if (-not $trimmed -or $trimmed.StartsWith('#')) { return }
|
||||
# Strip inline comments (e.g. "127.1.0.14 host.local # alias note")
|
||||
$noComment = ($trimmed -replace '\s+#.*$', '').Trim()
|
||||
if ($noComment) { $noComment }
|
||||
}
|
||||
|
||||
$missingLines = @()
|
||||
@@ -465,12 +469,29 @@ function Test-HostsFile {
|
||||
}
|
||||
} else {
|
||||
Write-Host ''
|
||||
Write-Host ' Stella Ops needs ~50 hosts file entries for local development.' -ForegroundColor Yellow
|
||||
Write-Host ' To install them, run this command in an elevated (Administrator) PowerShell:' -ForegroundColor Yellow
|
||||
Write-Warn '*** Stella Ops needs ~50 hosts file entries for local development. ***'
|
||||
Write-Warn "*** $($missingHosts.Count) host alias(es) are missing -- the platform will NOT work without them. ***"
|
||||
Write-Host ''
|
||||
Write-Host " Get-Content '$hostsSource' | Add-Content '$hostsPath'" -ForegroundColor White
|
||||
Write-Host ' Option 1: Re-run this script as Administrator to install them automatically.' -ForegroundColor Yellow
|
||||
Write-Host ''
|
||||
Write-Host ' Or re-run this script as Administrator to install them automatically.' -ForegroundColor Yellow
|
||||
Write-Host ' Option 2: Run the following in an elevated (Administrator) PowerShell:' -ForegroundColor Yellow
|
||||
Write-Host ''
|
||||
# Build a single-line PowerShell command that appends only the missing entries
|
||||
$escapedLines = ($missingLines | ForEach-Object { "`"$_`"" }) -join ', '
|
||||
Write-Host " @($escapedLines) | Add-Content -Path '$hostsPath'" -ForegroundColor White
|
||||
Write-Host ''
|
||||
|
||||
# Offer clipboard copy
|
||||
$copyAnswer = $null
|
||||
try { $copyAnswer = Read-Host ' Copy the missing entries to clipboard? (Y/n)' } catch {}
|
||||
if ($null -eq $copyAnswer -or $copyAnswer -eq '' -or $copyAnswer -match '^[Yy]') {
|
||||
try {
|
||||
($missingLines -join [Environment]::NewLine) | Set-Clipboard
|
||||
Write-Ok 'Missing host entries copied to clipboard. Paste them into the hosts file (run Notepad as Administrator).'
|
||||
} catch {
|
||||
Write-Warn 'Could not copy to clipboard. Please copy manually from above.'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,33 +542,42 @@ function Get-FrontdoorNetworkName {
|
||||
return 'stellaops_frontdoor'
|
||||
}
|
||||
|
||||
function Ensure-FrontdoorNetwork {
|
||||
$networkName = Get-FrontdoorNetworkName
|
||||
function Ensure-DockerNetwork([string]$networkName, [string]$label) {
|
||||
if ([string]::IsNullOrWhiteSpace($networkName)) {
|
||||
Write-Fail 'Unable to resolve the frontdoor Docker network name.'
|
||||
Write-Fail "Unable to resolve the $label Docker network name."
|
||||
exit 1
|
||||
}
|
||||
|
||||
$existingNetworks = @(docker network ls --format '{{.Name}}' 2>$null)
|
||||
if ($existingNetworks -contains $networkName) {
|
||||
Write-Ok "Frontdoor network available ($networkName)"
|
||||
Write-Ok "$label network available ($networkName)"
|
||||
return
|
||||
}
|
||||
|
||||
Write-Warn "Frontdoor network missing ($networkName); creating it now."
|
||||
Write-Warn "$label network missing ($networkName); creating it now."
|
||||
docker network create $networkName | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Fail "Failed to create frontdoor network ($networkName)."
|
||||
Write-Fail "Failed to create $label network ($networkName)."
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Ok "Created frontdoor network ($networkName)"
|
||||
Write-Ok "Created $label network ($networkName)"
|
||||
}
|
||||
|
||||
function Ensure-StellaOpsNetwork {
|
||||
Ensure-DockerNetwork 'stellaops' 'Stellaops'
|
||||
}
|
||||
|
||||
function Ensure-FrontdoorNetwork {
|
||||
$networkName = Get-FrontdoorNetworkName
|
||||
Ensure-DockerNetwork $networkName 'Frontdoor'
|
||||
}
|
||||
|
||||
# ─── 4. Start infrastructure ───────────────────────────────────────────────
|
||||
|
||||
function Start-Infrastructure {
|
||||
Write-Step 'Starting infrastructure containers (docker-compose.dev.yml)'
|
||||
Ensure-StellaOpsNetwork
|
||||
Push-Location $ComposeDir
|
||||
try {
|
||||
docker compose -f docker-compose.dev.yml up -d
|
||||
@@ -607,6 +637,7 @@ function Build-Images([switch]$PublishNoRestore) {
|
||||
|
||||
function Start-Platform {
|
||||
Write-Step 'Starting full Stella Ops platform'
|
||||
Ensure-StellaOpsNetwork
|
||||
Ensure-FrontdoorNetwork
|
||||
Push-Location $ComposeDir
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user