From c6ebb95ed3ad80776ef224c4851fc199a1462a69 Mon Sep 17 00:00:00 2001 From: CallMeR <9463297+callmer@user.noreply.gitee.com> Date: Thu, 28 Aug 2025 13:18:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20SmartDNS=20=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E8=84=9A=E6=9C=AC=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.PVE制作DNS服务器.md | 4 +- src/debian/debian_dns_dnsmasq_cron.conf | 4 +- src/debian/debian_dns_smartdns_cron.conf | 2 +- src/debian/debian_dns_smartdns_plugin.conf | 54 ++++++++++------------ 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/06.PVE制作DNS服务器.md b/06.PVE制作DNS服务器.md index 83c3394..94fb148 100644 --- a/06.PVE制作DNS服务器.md +++ b/06.PVE制作DNS服务器.md @@ -270,7 +270,7 @@ $ sudo chmod +x /usr/local/bin/smartdns-plugin.sh $ sudo chattr +i /usr/local/bin/smartdns-plugin.sh ## 执行脚本 -$ sudo bash /usr/local/bin/smartdns-plugin.sh +$ sudo /usr/local/bin/smartdns-plugin.sh ``` ### 6.2.定时任务 @@ -300,7 +300,7 @@ $ sudo crontab -e 20 9 * * * /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/smartdns.d/anti-ad.smartdns.conf https://anti-ad.net/anti-ad-for-smartdns.conf -30 9 * * * /usr/bin/bash /usr/local/bin/smartdns-plugin.sh +30 9 * * * /usr/local/bin/smartdns-plugin.sh ``` ### 6.3. SmartDNS 主配置 diff --git a/src/debian/debian_dns_dnsmasq_cron.conf b/src/debian/debian_dns_dnsmasq_cron.conf index 8e644f4..39f75da 100644 --- a/src/debian/debian_dns_dnsmasq_cron.conf +++ b/src/debian/debian_dns_dnsmasq_cron.conf @@ -8,11 +8,11 @@ $ sudo chmod +x /usr/local/bin/dnsmasq-plugin.sh $ sudo chattr +i /usr/local/bin/dnsmasq-plugin.sh ## 执行脚本 -$ sudo bash /usr/local/bin/dnsmasq-plugin.sh +$ sudo /usr/local/bin/dnsmasq-plugin.sh ## 设置 crontab 25 9 * * * /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/dnsmasq.d/anti-ad.dnsmasq.conf https://anti-ad.net/anti-ad-for-dnsmasq.conf -35 9 * * * /usr/bin/bash /usr/local/bin/dnsmasq-plugin.sh +35 9 * * * /usr/local/bin/dnsmasq-plugin.sh diff --git a/src/debian/debian_dns_smartdns_cron.conf b/src/debian/debian_dns_smartdns_cron.conf index ff66b75..c9c45ee 100644 --- a/src/debian/debian_dns_smartdns_cron.conf +++ b/src/debian/debian_dns_smartdns_cron.conf @@ -10,5 +10,5 @@ 20 9 * * * /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/smartdns.d/anti-ad.smartdns.conf https://anti-ad.net/anti-ad-for-smartdns.conf -30 9 * * * /usr/bin/bash /usr/local/bin/smartdns-plugin.sh +30 9 * * * /usr/local/bin/smartdns-plugin.sh diff --git a/src/debian/debian_dns_smartdns_plugin.conf b/src/debian/debian_dns_smartdns_plugin.conf index a4f3471..8270f5a 100644 --- a/src/debian/debian_dns_smartdns_plugin.conf +++ b/src/debian/debian_dns_smartdns_plugin.conf @@ -17,7 +17,7 @@ echo "Checking whether the configuration folder exists..." [ -d "$CONFDIR" ] || mkdir -p "$CONFDIR" echo "Downloading latest configurations..." -git clone --depth=1 https://gitee.com/felixonmars/dnsmasq-china-list.git "$WORKDIR" +git clone --depth=1 https://gitee.com/felixonmars/dnsmasq-china-list.git "$WORKDIR" || { echo "Git clone failed"; rm -rf "$WORKDIR"; exit 1; } #git clone --depth=1 https://pagure.io/dnsmasq-china-list.git "$WORKDIR" #git clone --depth=1 https://github.com/felixonmars/dnsmasq-china-list.git "$WORKDIR" #git clone --depth=1 https://bitbucket.org/felixonmars/dnsmasq-china-list.git "$WORKDIR" @@ -29,51 +29,45 @@ git clone --depth=1 https://gitee.com/felixonmars/dnsmasq-china-list.git "$WORKD echo "Removing old configurations..." for _conf in $CONF_WITH_SERVERS $CONF_WITH_GROUP $CONF_SIMPLE; do - rm -f "$CONFDIR/$_conf"*.conf + rm -f "$CONFDIR/$_conf"*.conf done echo "Installing new configurations..." for _conf in $CONF_WITH_SERVERS $CONF_WITH_GROUP $CONF_SIMPLE; do - case "$CONF_WITH_SERVERS" in - *"$_conf"*) - sed -n 's/^server=\/\([^\/]*\)\/114.114.114.114$/\1/p' "$WORKDIR/$_conf.conf" | grep -v '^#' > "$WORKDIR/$_conf.step1.raw" - sed -e "s/.*/nameserver \/&\/$GROUP/" "$WORKDIR/$_conf.step1.raw" > "$WORKDIR/$_conf.step2.raw" - cp "$WORKDIR/$_conf.step2.raw" "$CONFDIR/$_conf.smartdns.conf" - ;; - esac + if echo " $CONF_WITH_SERVERS " | grep -q " $_conf "; then + sed -n 's/^server=\/\([^\/]*\)\/114.114.114.114$/\1/p' "$WORKDIR/$_conf.conf" | grep -v '^#' > "$WORKDIR/$_conf.step1.raw" + sed -e "s/.*/nameserver \/&\/$GROUP/" "$WORKDIR/$_conf.step1.raw" > "$WORKDIR/$_conf.step2.raw" + cp "$WORKDIR/$_conf.step2.raw" "$CONFDIR/$_conf.smartdns.conf" + fi - case "$CONF_WITH_GROUP" in - *"$_conf"*) - for _server in $SERVERS; do - echo "server $_server -group $GROUP -exclude-default-group" >> "$WORKDIR/$_conf.raw" - done - cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.smartdns.conf" - ;; - esac + if echo " $CONF_WITH_GROUP " | grep -q " $_conf "; then + for _server in $SERVERS; do + echo "server $_server -group $GROUP -exclude-default-group" >> "$WORKDIR/$_conf.raw" + done + cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.smartdns.conf" + fi - case "$CONF_SIMPLE" in - *"$_conf"*) - sed -e "s/=/ /" "$WORKDIR/$_conf.conf" > "$WORKDIR/$_conf.raw" - cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.smartdns.conf" - ;; - esac + if echo " $CONF_SIMPLE " | grep -q " $_conf "; then + sed -e "s/=/ /" "$WORKDIR/$_conf.conf" > "$WORKDIR/$_conf.raw" + cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.smartdns.conf" + fi done echo "Restarting smartdns service..." if command -v systemctl >/dev/null 2>&1; then - systemctl restart smartdns + systemctl restart smartdns elif command -v service >/dev/null 2>&1; then - service smartdns restart + service smartdns restart elif command -v rc-service >/dev/null 2>&1; then - rc-service smartdns restart -elif command -v busybox >/dev/null 2>&1 && [ -d "/etc/init.d" ]; then - /etc/init.d/smartdns restart + rc-service smartdns restart +elif [ -x "/etc/init.d/smartdns" ]; then + /etc/init.d/smartdns restart else - echo "Now please restart smartdns since I don't know how to do it." + echo "Now please restart smartdns manually." fi echo "Cleaning up..." -rm -r "$WORKDIR" +rm -rf "$WORKDIR"