Discover Nightwing Move sources for Muninn

This commit is contained in:
Meta Vens 2026-06-14 15:18:08 +01:00
commit 3276e5fbd3
4 changed files with 91 additions and 9 deletions

View file

@ -0,0 +1,14 @@
param(
[string] $SshTarget = "nightwing"
)
$ErrorActionPreference = "Stop"
$scriptPath = Join-Path $PSScriptRoot "nightwing-move-state-sources.sh"
$command = 'ssh.exe -o BatchMode=yes -o ConnectTimeout=5 ' +
$SshTarget +
' "sh -s" < "' +
$scriptPath +
'"'
& cmd.exe /d /c $command
exit $LASTEXITCODE

View file

@ -3,12 +3,26 @@ param(
[string] $MuninnExe = "/home/metacrat/.local/bin/muninn",
[string] $StorePath = "/home/metacrat/.local/state/gamecult/muninn/muninn.telemetry.cc",
[string] $PidPath = "/home/metacrat/.local/state/gamecult/muninn/muninn.pid",
[string] $MoveState = "move-usb=/dev/input/by-id/usb-Sony_Computer_Entertainment_Motion_Controller-joystick",
[string[]] $MoveState = @(),
[int] $IntervalSeconds = 15
)
$ErrorActionPreference = "Stop"
function Quote-ShSingle([string] $Value) {
return "'" + ($Value -replace "'", "'\''") + "'"
}
$moveStateSpecs = @($MoveState | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
if ($moveStateSpecs.Count -eq 0) {
$sourceScript = Join-Path $PSScriptRoot "get-nightwing-move-state-sources.ps1"
$moveStateSpecs = @(& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $sourceScript -SshTarget $SshTarget)
}
$moveStateSetLines = ($moveStateSpecs | ForEach-Object {
"set -- ""`$@"" --move-state $(Quote-ShSingle $_)"
}) -join "`n"
$remoteScript = @"
set -eu
if [ ! -x '$MuninnExe' ]; then
@ -23,11 +37,13 @@ else
echo 'Muninn serve process is not running on Nightwing' >&2
exit 1
fi
'$MuninnExe' --health \
set -- --health \
--store '$StorePath' \
--host nightwing \
--move-state '$MoveState' \
--host nightwing
$moveStateSetLines
set -- "`$@" \
--interval-seconds '$IntervalSeconds'
'$MuninnExe' "`$@"
"@
ssh.exe -o BatchMode=yes -o ConnectTimeout=5 $SshTarget $remoteScript

View file

@ -0,0 +1,36 @@
#!/bin/sh
set -eu
for js in /dev/input/js*; do
[ -e "$js" ] || continue
props="$(udevadm info -q property -n "$js" 2>/dev/null || true)"
uevent="/sys/class/input/$(basename "$js")/device/device/uevent"
uevent_text="$(cat "$uevent" 2>/dev/null || true)"
case "$props
$uevent_text" in
*ID_VENDOR_ID=054c*ID_MODEL_ID=03d5*|*ID_MODEL=Motion_Controller*|*HID_ID=0005:0000054C:000003D5*|*HID_ID=0003:0000054C:000003D5*)
;;
*)
continue
;;
esac
bus="$(printf '%s\n' "$props" | awk -F= '$1=="ID_BUS"{print $2; exit}')"
uniq="$(printf '%s\n' "$uevent_text" | awk -F= '$1=="HID_UNIQ"{print $2; exit}' | tr -d ':')"
path_tag="$(printf '%s\n' "$props" | awk -F= '$1=="ID_PATH_TAG"{print $2; exit}' | tr -c 'A-Za-z0-9_' '_' | sed 's/_*$//')"
case "$bus:$uniq" in
bluetooth:?*)
id="move-bt-$uniq"
;;
*)
if [ -n "$path_tag" ]; then
id="move-usb-$path_tag"
else
id="move-$(basename "$js")"
fi
;;
esac
printf '%s=%s\n' "$id" "$js"
done

View file

@ -3,13 +3,27 @@ param(
[string] $MuninnExe = "/home/metacrat/.local/bin/muninn",
[string] $StorePath = "/home/metacrat/.local/state/gamecult/muninn/muninn.telemetry.cc",
[string] $LogRoot = "/home/metacrat/.local/state/gamecult/muninn",
[string] $MoveState = "move-usb=/dev/input/by-id/usb-Sony_Computer_Entertainment_Motion_Controller-joystick",
[string[]] $MoveState = @(),
[string] $MoveEvidenceStream = "muninn:nightwing:move-evidence",
[int] $IntervalSeconds = 15
)
$ErrorActionPreference = "Stop"
function Quote-ShSingle([string] $Value) {
return "'" + ($Value -replace "'", "'\''") + "'"
}
$moveStateSpecs = @($MoveState | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
if ($moveStateSpecs.Count -eq 0) {
$sourceScript = Join-Path $PSScriptRoot "get-nightwing-move-state-sources.ps1"
$moveStateSpecs = @(& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $sourceScript -SshTarget $SshTarget)
}
$moveStateSetLines = ($moveStateSpecs | ForEach-Object {
"set -- ""`$@"" --move-state $(Quote-ShSingle $_)"
}) -join "`n"
$remoteScript = @"
set -eu
mkdir -p '$LogRoot'
@ -24,13 +38,15 @@ fi
for pid in `$(pgrep -f '[m]uninn serve .*--host nightwing' 2>/dev/null || true); do
kill "`$pid" 2>/dev/null || true
done
nohup '$MuninnExe' serve \
set -- serve \
--store '$StorePath' \
--log-root '$LogRoot' \
--host nightwing \
--move-state '$MoveState' \
--host nightwing
$moveStateSetLines
set -- "`$@" \
--move-evidence-stream '$MoveEvidenceStream' \
--interval-seconds '$IntervalSeconds' \
--interval-seconds '$IntervalSeconds'
nohup '$MuninnExe' "`$@" \
> '$LogRoot/muninn-serve.out.log' \
2> '$LogRoot/muninn-serve.err.log' \
< /dev/null &