feat(bootstrap): set hostname in Phase 0

Rename the machine to the name in the bundle's identity.json (default GURU-5070,
override with -Hostname) when run as admin, with an end-of-run reboot reminder.
Ensures scheduled tasks, coord session IDs, and log attribution line up. RESTORE.md
documents the step.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-06 12:17:11 -07:00
parent 7342be1eaf
commit 974fb97f10
2 changed files with 27 additions and 0 deletions

View File

@@ -46,6 +46,7 @@ param(
[string]$GiteaHost = 'https://git.azcomputerguru.com',
[string]$ClaudeToolsRoot = 'D:\claudetools',
[string]$VaultRoot = 'D:\vault',
[string]$Hostname, # target computer name; default = identity.json .machine, else GURU-5070
[string]$OnlyPhases
)
$ErrorActionPreference = 'Stop'
@@ -72,6 +73,21 @@ if (Phase 0 'Preflight') {
Ok "winget present: $((Get-Command winget).Source)"
$script:Bundle = Find-Bundle
if ($script:Bundle) { Ok "recovery bundle: $script:Bundle" } else { Warn "no recovery bundle found - secret/identity restore phases will be skipped" }
# Hostname - a fresh Windows install is DESKTOP-xxxxx; identity.json + scheduled tasks
# + coord session IDs all expect the real name. Rename needs admin and a reboot to apply.
$target = $Hostname
if (-not $target -and $script:Bundle -and (Test-Path "$script:Bundle\identity\identity.json")) {
try { $target = (Get-Content "$script:Bundle\identity\identity.json" -Raw | ConvertFrom-Json).machine } catch {}
}
if (-not $target) { $target = 'GURU-5070' }
if ($env:COMPUTERNAME -ne $target) {
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
if ($isAdmin) {
try { Rename-Computer -NewName $target -Force -ErrorAction Stop; $script:RebootNeeded = $true; Ok "hostname: $env:COMPUTERNAME -> $target (takes effect after reboot)" }
catch { Warn "rename to '$target' failed: $($_.Exception.Message)" }
} else { Warn "hostname is '$env:COMPUTERNAME', target '$target' - run this script as Administrator to rename (or manually: Rename-Computer -NewName $target -Restart)" }
} else { Ok "hostname already '$target'" }
}
# ============================================================ PHASE 1
@@ -270,4 +286,8 @@ if (Phase 11 'Verify') {
Write-Host " Verify vault: bash $ClaudeToolsRoot/.claude/scripts/vault.sh list"
}
if ($script:RebootNeeded) {
Write-Host "`n[REBOOT] Hostname was changed to '$target' - REBOOT for it to take effect." -ForegroundColor Yellow
Write-Host " (scheduled tasks + coord session IDs read the hostname, so reboot before relying on them)"
}
Write-Host "`n[DONE] windows-bootstrap.ps1 complete." -ForegroundColor Green