Files
server-manager/install/agent-uninstall.sh
Agent 0edc882f2e 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
2026-06-11 19:07:14 -04:00

30 lines
884 B
Bash

#!/bin/bash
# ServerManager Agent Uninstaller
# 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"
SERVICE_FILE="/etc/systemd/system/servermanager-agent.service"
echo "[1/3] Stopping and disabling service..."
systemctl stop servermanager-agent 2>/dev/null || true
systemctl disable servermanager-agent 2>/dev/null || true
systemctl daemon-reload 2>/dev/null || true
echo "[2/3] Removing files..."
rm -f "$AGENT_BIN" 2>/dev/null || true
rm -rf "$CONFIG_DIR" 2>/dev/null || true
rm -f "$SERVICE_FILE" 2>/dev/null || true
echo "[3/3] Reloading systemd..."
systemctl daemon-reload 2>/dev/null || true
echo "ServerManager Agent uninstalled successfully."