Add uninstall.sh

This commit is contained in:
2026-03-12 08:56:55 +00:00
parent 3101cb8d88
commit 53b13ddcef

44
uninstall.sh Normal file
View File

@@ -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."