fix: installer self-elevates with script PTY instead of external sudo chain

- agent-install.sh and agent-uninstall.sh now detect if running as root
  at startup and re-execute via 'script -qc sudo bash' if needed
- AgentService commands simplified: just write to /tmp and run bash,
  the scripts handle privilege escalation internally
- Fixes exit code propagation: the script's exit code now correctly
  flows back through exec -> script -> sudo -> bash -> SSH
This commit is contained in:
2026-06-11 19:07:14 -04:00
parent 0ce24c4b8f
commit 0edc882f2e
3 changed files with 18 additions and 6 deletions

View File

@@ -1,7 +1,6 @@
#!/bin/bash
# ServerManager Agent Installer
# Usage: bash agent-install.sh <SERVER_URL> <AGENT_KEY> [INTERVAL]
set -e
SERVER_URL="${1:-}"
AGENT_KEY="${2:-}"
@@ -12,6 +11,14 @@ if [ -z "$SERVER_URL" ] || [ -z "$AGENT_KEY" ]; then
exit 1
fi
# Self-elevate if not running as root
if [ "$(id -u)" -ne 0 ]; then
if command -v script >/dev/null 2>&1; then
exec script -q -c "sudo bash '$0' '$1' '$2' '$3'" /dev/null
fi
exec sudo bash "$0" "$@"
fi
AGENT_BIN="/usr/local/bin/servermanager-agent"
CONFIG_DIR="/etc/servermanager"
CONFIG_FILE="$CONFIG_DIR/agent.conf"

View File

@@ -1,6 +1,13 @@
#!/bin/bash
# ServerManager Agent Uninstaller
set -e
# Self-elevate if not running as root
if [ "$(id -u)" -ne 0 ]; then
if command -v script >/dev/null 2>&1; then
exec script -q -c "sudo bash '$0'" /dev/null
fi
exec sudo bash "$0"
fi
AGENT_BIN="/usr/local/bin/servermanager-agent"
CONFIG_DIR="/etc/servermanager"