feat: add --remove flag to install.sh for clean uninstall
This commit is contained in:
parent
b360ffd6af
commit
e1260ba5d3
1 changed files with 74 additions and 0 deletions
74
install.sh
74
install.sh
|
|
@ -5,6 +5,7 @@
|
||||||
#
|
#
|
||||||
# Usage: curl -sSL https://git.lohmar.co.uk/cclohmar/zoraxy-dhcp/raw/branch/main/install.sh | sudo bash
|
# Usage: curl -sSL https://git.lohmar.co.uk/cclohmar/zoraxy-dhcp/raw/branch/main/install.sh | sudo bash
|
||||||
# or: sudo bash install.sh
|
# or: sudo bash install.sh
|
||||||
|
# or: sudo bash install.sh --remove (clean uninstall)
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
|
@ -575,11 +576,84 @@ verify() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#==============================================================================
|
||||||
|
# REMOVE / UNINSTALL
|
||||||
|
#==============================================================================
|
||||||
|
|
||||||
|
remove_all() {
|
||||||
|
echo -e "${YELLOW}========================================${NC}"
|
||||||
|
echo -e "${YELLOW} Removing Zoraxy DHCP Setup${NC}"
|
||||||
|
echo -e "${YELLOW}========================================${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Stop services
|
||||||
|
log "Stopping services..."
|
||||||
|
systemctl stop dnsmasq 2>/dev/null || service dnsmasq stop 2>/dev/null || true
|
||||||
|
systemctl disable dnsmasq 2>/dev/null || true
|
||||||
|
systemctl stop zoraxy-dhcp-routing 2>/dev/null || true
|
||||||
|
systemctl disable zoraxy-dhcp-routing 2>/dev/null || true
|
||||||
|
systemctl stop gateway-routing 2>/dev/null || true
|
||||||
|
systemctl disable gateway-routing 2>/dev/null || true
|
||||||
|
|
||||||
|
# Remove packages (OS-aware)
|
||||||
|
log "Removing dnsmasq package..."
|
||||||
|
case "$OS_ID" in
|
||||||
|
debian|ubuntu|raspbian|linuxmint)
|
||||||
|
apt-get purge -y -qq dnsmasq 2>/dev/null || true ;;
|
||||||
|
rhel|centos|fedora|rocky|almalinux|amzn)
|
||||||
|
dnf remove -y dnsmasq 2>/dev/null || yum remove -y dnsmasq 2>/dev/null || true ;;
|
||||||
|
alpine) apk del dnsmasq 2>/dev/null || true ;;
|
||||||
|
opensuse*|sles) zypper remove -y dnsmasq 2>/dev/null || true ;;
|
||||||
|
arch|manjaro) pacman -R --noconfirm dnsmasq 2>/dev/null || true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Remove service files
|
||||||
|
log "Removing service files..."
|
||||||
|
rm -f /etc/systemd/system/zoraxy-dhcp-routing.service
|
||||||
|
rm -f /etc/systemd/system/gateway-routing.service
|
||||||
|
systemctl daemon-reload 2>/dev/null || true
|
||||||
|
|
||||||
|
# Flush NAT rules
|
||||||
|
log "Flushing iptables NAT rules..."
|
||||||
|
iptables -t nat -F POSTROUTING 2>/dev/null || true
|
||||||
|
|
||||||
|
# Remove config files
|
||||||
|
log "Removing config files..."
|
||||||
|
rm -rf /opt/zoraxy/conf/dhcp/ 2>/dev/null || true
|
||||||
|
rm -f /root/.dnsmasq-setup.conf /root/routing.sh
|
||||||
|
rm -f /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
|
||||||
|
rm -rf /etc/dnsmasq.d/ 2>/dev/null || true
|
||||||
|
|
||||||
|
# Remove sudoers
|
||||||
|
log "Removing sudoers rule..."
|
||||||
|
rm -f /etc/sudoers.d/dnsmasq-edit 2>/dev/null || true
|
||||||
|
|
||||||
|
# Remove group (only if empty)
|
||||||
|
if getent group dnsmasq-edit >/dev/null 2>&1; then
|
||||||
|
groupdel dnsmasq-edit 2>/dev/null || warn "Could not delete group 'dnsmasq-edit' (may have members)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN} ✅ Removal complete.${NC}"
|
||||||
|
echo -e "${GREEN} System is in a clean state — ready for fresh install.${NC}"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
# MAIN
|
# MAIN
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
# --- Argument parsing ---
|
||||||
|
if [[ "${1:-}" == "--remove" || "${1:-}" == "-r" ]]; then
|
||||||
|
banner
|
||||||
|
ensure_root "$@"
|
||||||
|
detect_os
|
||||||
|
remove_all
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Normal install flow ---
|
||||||
banner
|
banner
|
||||||
ensure_root "$@"
|
ensure_root "$@"
|
||||||
detect_os
|
detect_os
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue