Odin/scripts/deploy-raven-sleipnir.ps1
Meta Vens 515a864ef0 Rebase Idunn actuator scripts off the projects root
The previous commit fixed the target catalog and the operator alarm, but the
actuators the catalog invokes carried the same E: paths. Idunn would have
resolved every target and then failed on the first restart or deploy it ran,
for exactly the reason the alarm failed.

Rebased 41 references across 27 scripts:

- .cmd bodies invoke their sibling .ps1 through %~dp0 instead of an absolute
  drive path, and restart-weksa.cmd reaches its sibling repo the same way.
- .ps1 parameter defaults and assignments derive from $PSScriptRoot: one level
  up for paths inside Odin, two for sibling repos under the projects root.

Left deliberately alone: $RemoteViliRoot and $StateRoot in restart-vili.ps1.
Both are consumed inside the EncodedCommand block that restart-vili ssh's to
raven, so they describe raven's filesystem, not starfire's. Whether raven also
moved off E: is an operator question, not something to infer from here.

Verified: all 46 scripts under scripts/ parse clean, and the derivation
resolves to F:\Projects\Odin and F:\Projects on this host.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 01:05:40 +02:00

92 lines
3.4 KiB
PowerShell

param(
[string] $LocalSleipnirExe = (Join-Path (Split-Path -Parent $PSScriptRoot) "target\release\sleipnir.exe"),
[string] $RavenHost = "raven",
[string] $RemoteSleipnirExe = "C:\Meta\Odin\Sleipnir\sleipnir.exe",
[string] $SshUser = "madman's lullaby",
[string] $IdentityFile = "C:\Users\Meta\.ssh\id_ed25519_192_168_1_84",
[int] $ConnectTimeoutSeconds = 10
)
$ErrorActionPreference = "Stop"
if ($env:IDUNN_ACTUATOR -ne "1" -or $env:IDUNN_COMMAND_AUTHORITY -ne "idunn-daemon") {
throw "deploy-raven-sleipnir.ps1 is an Idunn actuator body. Deploy by poking Idunn; direct binary copy is not an owned path."
}
if (-not (Test-Path -LiteralPath $LocalSleipnirExe)) {
throw "Local Sleipnir release binary not found at $LocalSleipnirExe"
}
function ConvertTo-PowerShellStringLiteral {
param([Parameter(Mandatory = $true)] [string] $Value)
return "'" + $Value.Replace("'", "''") + "'"
}
function Get-SshTarget {
if ([string]::IsNullOrWhiteSpace($SshUser)) {
return $RavenHost
}
return "${SshUser}@${RavenHost}"
}
$sshArgs = @(
"-o", "BatchMode=yes",
"-o", "ConnectTimeout=$ConnectTimeoutSeconds",
"-o", "ConnectionAttempts=1"
)
if (-not [string]::IsNullOrWhiteSpace($IdentityFile)) {
$sshArgs += @("-i", $IdentityFile)
}
$target = Get-SshTarget
$remoteNew = "$RemoteSleipnirExe.new"
$remoteDir = Split-Path -Parent $RemoteSleipnirExe
$remoteNewSftp = $remoteNew.Replace("\", "/")
$prepare = @"
`$ErrorActionPreference = "Stop"
`$ProgressPreference = "SilentlyContinue"
New-Item -ItemType Directory -Force -Path $(ConvertTo-PowerShellStringLiteral $remoteDir) | Out-Null
Get-CimInstance Win32_Process |
Where-Object { `$_.Name -ieq "sleipnir.exe" } |
ForEach-Object { taskkill.exe /PID `$_.ProcessId /T /F | Out-Null }
Remove-Item -LiteralPath $(ConvertTo-PowerShellStringLiteral $remoteNew) -Force -ErrorAction SilentlyContinue
exit 0
"@
$encodedPrepare = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($prepare))
& ssh.exe @sshArgs $target "powershell.exe -NoProfile -ExecutionPolicy Bypass -EncodedCommand $encodedPrepare"
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
$sftpBatch = New-TemporaryFile
try {
$sftpLines = @(
"put `"$LocalSleipnirExe`" `"$remoteNewSftp`""
)
Set-Content -LiteralPath $sftpBatch.FullName -Value $sftpLines -Encoding ASCII
& sftp.exe @sshArgs -b $sftpBatch.FullName $target
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
} finally {
Remove-Item -LiteralPath $sftpBatch.FullName -Force -ErrorAction SilentlyContinue
}
$install = @"
`$ErrorActionPreference = "Stop"
`$ProgressPreference = "SilentlyContinue"
if (Test-Path -LiteralPath $(ConvertTo-PowerShellStringLiteral $RemoteSleipnirExe)) {
Remove-Item -LiteralPath $(ConvertTo-PowerShellStringLiteral $RemoteSleipnirExe) -Force
}
Move-Item -LiteralPath $(ConvertTo-PowerShellStringLiteral $remoteNew) -Destination $(ConvertTo-PowerShellStringLiteral $RemoteSleipnirExe) -Force
exit 0
"@
$encodedInstall = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($install))
& ssh.exe @sshArgs $target "powershell.exe -NoProfile -ExecutionPolicy Bypass -EncodedCommand $encodedInstall"
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
& "$PSScriptRoot\restart-raven-sleipnir.ps1" -RavenHost $RavenHost -SleipnirExe $RemoteSleipnirExe -SshUser $SshUser -IdentityFile $IdentityFile -ConnectTimeoutSeconds $ConnectTimeoutSeconds
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}