#!/usr/bin/env bash
# Sourced by the scripts that run commands on the account. Refuses unless the
# remote shell's `whoami` is the cPanel user the resolved profile expects, so a
# wrong key or host can never reach another account. It does not choose the
# account: that is resolve-account.mjs (pin, AWESOMATE_ACCOUNT or --account).
# Needs $K $P $U $H $ACCT set by resolve-account.mjs --ssh.
assert_remote_user() {
  local remote
  remote="$(ssh -n -i "$K" -p "$P" -o StrictHostKeyChecking=accept-new -o BatchMode=yes "$U@$H" whoami 2>/dev/null | tail -n1 | tr -d '\r\n')" || remote=""
  if [ "$remote" != "$U" ]; then
    echo "✗ Refusing: account '$ACCT' expects cPanel user '$U' but the server answered '${remote:-nothing}'. Nothing was run." >&2
    return 1
  fi
}
