#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash -p nettools -p systemd

target="$1"
shift

host="$(hostname)"
if [ "$host" = "$target" ]
then
  # N.B.: anything other than just `reboot` with no args requires `sudo` privileges (to write to /run/systemd/).
  # `systemctl reboot -i` tells systemd to ignore inhibitors (i.e. other users logged in).
  timeout 5 reboot "$@" || \
    timeout 5 systemctl reboot -i "$@" || \
    (sync && reboot --force --force "$@")  #< XXX: requires root
else
  echo "WRONG MACHINE. you're on $host."
  exit 1
fi

