优化 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
@@ -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
+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
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"
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"