diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000..36d4ba6 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,44 @@ + + + #!/usr/bin/env bash + # ControlD MDM Agent — Uninstaller (macOS / Linux) + set -euo pipefail + + echo "[*] Uninstalling ControlD MDM agent..." + + OS="$(uname -s)" + + # Stop and remove daemon/service + if [ "${OS}" = "Darwin" ]; then + PLIST="/Library/LaunchDaemons/com.controld.agent.plist" + if [ -f "${PLIST}" ]; then + launchctl unload -w "${PLIST}" 2>/dev/null || true + rm -f "${PLIST}" + fi + SERVICES=$(networksetup -listallnetworkservices | tail -n +2) + while IFS= read -r svc; do + networksetup -setdnsservers "$svc" empty 2>/dev/null || true + done <<< "$SERVICES" + rm -f /etc/resolver/default + else + if systemctl is-active --quiet controld-agent.service 2>/dev/null; then + systemctl stop controld-agent.service + systemctl disable controld-agent.service + fi + rm -f /etc/systemd/system/controld-agent.service + systemctl daemon-reload 2>/dev/null || true + + if [ -f /etc/systemd/resolved.conf.d/controld.conf ]; then + rm -f /etc/systemd/resolved.conf.d/controld.conf + systemctl restart systemd-resolved 2>/dev/null || true + elif [ -f /etc/resolv.conf.bak ]; then + mv /etc/resolv.conf.bak /etc/resolv.conf + fi + fi + + HEARTBEAT="/opt/controld/heartbeat.sh" + (crontab -l 2>/dev/null | grep -v "${HEARTBEAT}") | crontab - 2>/dev/null || true + + rm -rf /opt/controld + + echo "[+] Uninstall complete. DNS settings restored."