diff --git a/bin/lib/remote.nu b/bin/lib/remote.nu index e5184e5..0901a70 100644 --- a/bin/lib/remote.nu +++ b/bin/lib/remote.nu @@ -213,29 +213,6 @@ export def "skyg remote status all" [] { return ($results | select host status reboot_pending needs_build) } -# Poll SSH until the host reaches the desired reachability, or the timeout elapses. -def wait-for-host [target: string, want_online: bool, timeout: int] { - let deadline = (date now) + ($timeout * 1sec) - while (date now) < $deadline { - let online = (try { - bash -c $"ssh -o BatchMode=yes -o ConnectTimeout=3 ($target) 'true' >/dev/null 2>&1" - true - } catch { false }) - if $online == $want_online { - return true - } - sleep 3sec - } - false -} - -# Send a desktop notification if notify-send is available; never fail the caller. -def notify [title: string, body: string] { - try { - ^notify-send $title $body - } catch { } -} - # Reboot every remote host that is pending a reboot (booted-system != current-system). # Detects pending hosts, lists them, asks for confirmation, then reboots each one at a # time, waiting for it to come back online and sending a desktop notification when it does. diff --git a/bin/lib/remote.utils.nu b/bin/lib/remote.utils.nu index c80cf0d..f8f556e 100644 --- a/bin/lib/remote.utils.nu +++ b/bin/lib/remote.utils.nu @@ -34,3 +34,27 @@ export def get-remote-boot-info [ host: string@remote_targets ] { {host: $host, status: "error", booted: "", current: "", reboot_pending: false, needs_build: false, local_toplevel: ""} }) } + + +# Poll SSH until the host reaches the desired reachability, or the timeout elapses. +def wait-for-host [target: string, want_online: bool, timeout: int] { + let deadline = (date now) + ($timeout * 1sec) + while (date now) < $deadline { + let online = (try { + bash -c $"ssh -o BatchMode=yes -o ConnectTimeout=3 ($target) 'true' >/dev/null 2>&1" + true + } catch { false }) + if $online == $want_online { + return true + } + sleep 3sec + } + false +} + +# Send a desktop notification if notify-send is available; never fail the caller. +def notify [title: string, body: string] { + try { + ^notify-send $title $body + } catch { } +}