#!/usr/bin/env bash
# Forced command for the Void's restricted key on Z (installed in root's
# authorized_keys via command="..."). Maps a whitelisted service-restart action
# id to a FIXED `pct exec ... systemctl restart`. The id arrives via
# SSH_ORIGINAL_COMMAND; nothing else is honoured — no input is interpolated into a
# command. Guest power goes through the Proxmox API, NOT this wrapper. Keep the
# case list in sync with config/actions.json (service_restart entries).
#
# Install on Z:
#   install -m 755 void-act /usr/local/bin/void-act
#   # prefix the Void's pubkey in /root/.ssh/authorized_keys with:
#   command="/usr/local/bin/void-act",no-port-forwarding,no-pty,no-X11-forwarding,no-agent-forwarding <pubkey>
set -euo pipefail
case "${SSH_ORIGINAL_COMMAND:-}" in
  restart-pihole)      exec pct exec 106 -- systemctl restart pihole-FTL ;;
  restart-gitea)       exec pct exec 105 -- systemctl restart gitea ;;
  restart-n8n)         exec pct exec 110 -- systemctl restart n8n ;;
  restart-magicmirror) exec pct exec 111 -- systemctl restart magicmirror ;;
  *) echo "void-act: refused '${SSH_ORIGINAL_COMMAND:-}'" >&2; exit 13 ;;
esac
