Files
cairnobs/internal/server/install.ps1
T
jcoffey-dev a1ad48070c
ci / check (pull_request) Successful in 7m17s
ci / postgres (pull_request) Successful in 10m48s
Windows: the machine's certificate stores in the inventory, and arm64
A Windows agent reads LocalMachine\My and WebHosting (cert_stores) itself,
read-only, every ten minutes: certificates only, never a key. They join the
inventory as places of kind "store" at Cert:\LocalMachine\<store>\<thumbprint>
and are judged as files are, so an IIS or RDP binding still serving the old
certificate after a renewal shows as renewed but not reloaded.

The release gets a windows_arm64 zip; install.ps1 picks by the machine's
architecture and the packages route serves both.

Run on the Windows Server 2025 VM as the service's own account.
2026-11-15 02:42:24 -07:00

60 lines
3.3 KiB
PowerShell

# Cairn OBS: install obs-beacon-agent on this Windows host and join it to
# the obs-beacond that served this script. In PowerShell as Administrator:
#
# & ([scriptblock]::Create((irm https://<server>/install.ps1))) -Join <token>
#
# Options: -Join <token> (from Hosts, Add host), -Packages <url> (where the
# agent's zip and SHA256SUMS are), -Force (replace an existing agent.yaml).
# It throws rather than exits: run as a script block, exit would close the
# PowerShell window it was pasted into.
param([string]$Join = '', [string]$Packages = '', [switch]$Force)
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
$Version = @VERSION@
if (-not $Packages) { $Packages = @PACKAGES@ }
$Packages = $Packages.TrimEnd('/')
function Say([string]$m) { Write-Host "obs-beacon install: $m" }
if (-not $Join) { throw 'run it with -Join <token>: Hosts, Add host in the web interface makes one' }
$me = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
if (-not $me.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw 'run it in PowerShell as Administrator' }
# The machine's architecture, also from a 32-bit PowerShell (which says x86).
$cpu = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }
$arch = @{ AMD64 = 'amd64'; ARM64 = 'arm64' }[$cpu]
if (-not $arch) { throw "no agent for $cpu" }
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$exe = Join-Path $env:ProgramFiles 'Cairn OBS\obs-beacon-agent.exe'
if (Test-Path $exe) {
Say "obs-beacon-agent is installed already: $(& $exe -version)"
} else {
if (-not $Packages) { throw "this server doesn't say where agent packages are (join.packages_dir or join.packages_url in obs-beacond.yaml). Install the agent from its zip by hand (README.txt in it), then: obs-beacon-agent.exe join <token>" }
$file = "obs-beacon-agent_$($Version.TrimStart('v'))_windows_$arch.zip"
$tmp = Join-Path ([IO.Path]::GetTempPath()) ('obs-beacon-' + [guid]::NewGuid())
New-Item -ItemType Directory -Path $tmp | Out-Null
try {
Say "fetching $file from $Packages"
Invoke-WebRequest -UseBasicParsing -Uri "$Packages/SHA256SUMS" -OutFile (Join-Path $tmp 'SHA256SUMS')
Invoke-WebRequest -UseBasicParsing -Uri "$Packages/$file" -OutFile (Join-Path $tmp $file)
$line = Get-Content (Join-Path $tmp 'SHA256SUMS') | Where-Object { ($_ -split '\s+')[1] -eq $file } | Select-Object -First 1
if (-not $line) { throw "$file isn't in SHA256SUMS" }
$want = ($line -split '\s+')[0].ToLower()
$got = (Get-FileHash -Algorithm SHA256 -Path (Join-Path $tmp $file)).Hash.ToLower()
if ($got -ne $want) { throw "$file doesn't match SHA256SUMS" }
Expand-Archive -Path (Join-Path $tmp $file) -DestinationPath (Join-Path $tmp 'zip')
& (Join-Path $tmp 'zip\obs-beacon-agent.exe') service install
if ($LASTEXITCODE -ne 0) { throw 'service install failed' }
} finally {
Remove-Item -Recurse -Force -Path $tmp -ErrorAction SilentlyContinue
}
Say "installed $(& $exe -version)"
}
$joinArgs = @('join')
if ($Force) { $joinArgs += '-force' }
$joinArgs += $Join
& $exe @joinArgs
if ($LASTEXITCODE -ne 0) { throw 'join failed' }
Restart-Service -Name obs-beacon-agent
Say 'done: obs-beacon-agent is running and reporting'