#!/bin/bash # ======================================== # DHCP & DNS 管理器 - Linux 卸载脚本 # ======================================== set -e INSTALL_DIR="/opt/dhcp-dns-manager" SERVICE_NAME="dhcp-dns-manager" echo "⚠️ 警告:这将卸载 DHCP & DNS 管理器" echo "" read -p "是否继续?(y/N): " confirm if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then echo "已取消" exit 0 fi # 停止服务 echo "🛑 停止服务..." systemctl stop $SERVICE_NAME || true systemctl disable $SERVICE_NAME || true # 删除 systemd 服务 echo "🗑️ 删除 systemd 服务..." rm -f /etc/systemd/system/$SERVICE_NAME.service systemctl daemon-reload # 删除安装目录 echo "🗑️ 删除安装目录..." rm -rf $INSTALL_DIR # 删除防火墙规则 echo "🔥 清理防火墙规则..." if command -v ufw &> /dev/null; then ufw delete allow 53/udp || true ufw delete allow 67/udp || true ufw delete allow 8080/tcp || true elif command -v firewall-cmd &> /dev/null; then firewall-cmd --permanent --remove-port=53/udp || true firewall-cmd --permanent --remove-port=67/udp || true firewall-cmd --permanent --remove-port=8080/tcp || true firewall-cmd --reload || true fi echo "" echo "✅ 卸载完成!" echo "" echo "注意:数据库文件已删除,如需保留请提前备份:" echo " $INSTALL_DIR/data/dhcp-dns.db" echo ""