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:
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user