优化 SmartDNS 插件脚本兼容性

This commit is contained in:
CallMeR
2025-08-28 13:18:04 +08:00
parent 4aaa101400
commit c6ebb95ed3
4 changed files with 29 additions and 35 deletions
+2 -2
View File
@@ -270,7 +270,7 @@ $ sudo chmod +x /usr/local/bin/smartdns-plugin.sh
$ sudo chattr +i /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.定时任务 ### 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 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 主配置 ### 6.3. SmartDNS 主配置
+2 -2
View File
@@ -8,11 +8,11 @@ $ sudo chmod +x /usr/local/bin/dnsmasq-plugin.sh
$ sudo chattr +i /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 ## 设置 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 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
+1 -1
View File
@@ -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 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
+24 -30
View File
@@ -17,7 +17,7 @@ echo "Checking whether the configuration folder exists..."
[ -d "$CONFDIR" ] || mkdir -p "$CONFDIR" [ -d "$CONFDIR" ] || mkdir -p "$CONFDIR"
echo "Downloading latest configurations..." 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://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://github.com/felixonmars/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 https://bitbucket.org/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..." echo "Removing old configurations..."
for _conf in $CONF_WITH_SERVERS $CONF_WITH_GROUP $CONF_SIMPLE; do for _conf in $CONF_WITH_SERVERS $CONF_WITH_GROUP $CONF_SIMPLE; do
rm -f "$CONFDIR/$_conf"*.conf rm -f "$CONFDIR/$_conf"*.conf
done done
echo "Installing new configurations..." echo "Installing new configurations..."
for _conf in $CONF_WITH_SERVERS $CONF_WITH_GROUP $CONF_SIMPLE; do for _conf in $CONF_WITH_SERVERS $CONF_WITH_GROUP $CONF_SIMPLE; do
case "$CONF_WITH_SERVERS" in if echo " $CONF_WITH_SERVERS " | grep -q " $_conf "; then
*"$_conf"*) sed -n 's/^server=\/\([^\/]*\)\/114.114.114.114$/\1/p' "$WORKDIR/$_conf.conf" | grep -v '^#' > "$WORKDIR/$_conf.step1.raw"
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"
sed -e "s/.*/nameserver \/&\/$GROUP/" "$WORKDIR/$_conf.step1.raw" > "$WORKDIR/$_conf.step2.raw" cp "$WORKDIR/$_conf.step2.raw" "$CONFDIR/$_conf.smartdns.conf"
cp "$WORKDIR/$_conf.step2.raw" "$CONFDIR/$_conf.smartdns.conf" fi
;;
esac
case "$CONF_WITH_GROUP" in if echo " $CONF_WITH_GROUP " | grep -q " $_conf "; then
*"$_conf"*) for _server in $SERVERS; do
for _server in $SERVERS; do echo "server $_server -group $GROUP -exclude-default-group" >> "$WORKDIR/$_conf.raw"
echo "server $_server -group $GROUP -exclude-default-group" >> "$WORKDIR/$_conf.raw" done
done cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.smartdns.conf"
cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.smartdns.conf" fi
;;
esac
case "$CONF_SIMPLE" in if echo " $CONF_SIMPLE " | grep -q " $_conf "; then
*"$_conf"*) sed -e "s/=/ /" "$WORKDIR/$_conf.conf" > "$WORKDIR/$_conf.raw"
sed -e "s/=/ /" "$WORKDIR/$_conf.conf" > "$WORKDIR/$_conf.raw" cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.smartdns.conf"
cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.smartdns.conf" fi
;;
esac
done done
echo "Restarting smartdns service..." echo "Restarting smartdns service..."
if command -v systemctl >/dev/null 2>&1; then if command -v systemctl >/dev/null 2>&1; then
systemctl restart smartdns systemctl restart smartdns
elif command -v service >/dev/null 2>&1; then 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 elif command -v rc-service >/dev/null 2>&1; then
rc-service smartdns restart rc-service smartdns restart
elif command -v busybox >/dev/null 2>&1 && [ -d "/etc/init.d" ]; then elif [ -x "/etc/init.d/smartdns" ]; then
/etc/init.d/smartdns restart /etc/init.d/smartdns restart
else else
echo "Now please restart smartdns since I don't know how to do it." echo "Now please restart smartdns manually."
fi fi
echo "Cleaning up..." echo "Cleaning up..."
rm -r "$WORKDIR" rm -rf "$WORKDIR"