更新 SmartDNS 插件脚本

This commit is contained in:
CallMeR
2023-12-08 23:42:25 +08:00
parent 454ae86aba
commit 6aa24ecb61
@@ -0,0 +1,72 @@
#!/bin/bash
set -e
WORKDIR="$(mktemp -d)"
CONFIG_DIR="/etc/smartdns.d"
SERVERS=(223.5.5.5 119.29.29.29 114.114.114.114 114.114.115.115)
SERVERS_GROUP=(accelerate)
# Others: 223.6.6.6 119.28.28.28
# Not using best possible CDN pop: 1.2.4.8 210.2.4.8
# Broken?: 180.76.76.76
CONF_WITH_SERVERS=(accelerated-domains.china google.china apple.china)
CONF_WITH_GROUP=(server-group.china)
CONF_SIMPLE=(bogus-nxdomain.china)
echo "Checking whether the configuration folder exists..."
if [ ! -d "$CONFIG_DIR" ]; then
mkdir -p "$CONFIG_DIR"
fi
echo "Downloading latest configurations..."
git clone --depth=1 https://gitee.com/felixonmars/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://bitbucket.org/felixonmars/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 https://gitlab.com/felixonmars/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 https://e.coding.net/felixonmars/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 https://codehub.devcloud.huaweicloud.com/dnsmasq-china-list00001/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 http://repo.or.cz/dnsmasq-china-list.git "$WORKDIR"
echo "Removing old configurations..."
for _conf in "${CONF_WITH_SERVERS[@]}" "${CONF_WITH_GROUP[@]}" "${CONF_SIMPLE[@]}"; do
rm -f /etc/smartdns.d/"$_conf"*.conf
done
echo "Installing new configurations..."
for conf in "${CONF_WITH_SERVERS[@]}" "${CONF_WITH_GROUP[@]}" "${CONF_SIMPLE[@]}"; do
if [[ "${CONF_WITH_SERVERS[@]}" =~ $conf ]]; then
sed -En 's|^server=/([^/]*)/114.114.114.114$|\1|p' "$WORKDIR/$conf.conf" | grep -Ev '^#' > "$WORKDIR/$conf.step1.raw"
sed -En "s/(.*)/nameserver \\/\\1\\/${SERVERS_GROUP[@]}/p" "$WORKDIR/$conf.step1.raw" > "$WORKDIR/$conf.step2.raw"
cp "$WORKDIR/$conf.step2.raw" "/etc/smartdns.d/$conf.${SERVERS_GROUP[@]}.conf"
fi
if [[ "${CONF_WITH_GROUP[@]}" =~ $conf ]]; then
for server in "${SERVERS[@]}"; do
echo "server $server -group ${SERVERS_GROUP[@]} -exclude-default-group" >> "$WORKDIR/$conf.raw"
done
cp "$WORKDIR/$conf.raw" "/etc/smartdns.d/${CONF_WITH_GROUP[@]}.${SERVERS_GROUP[@]}.conf"
fi
if [[ "${CONF_SIMPLE[@]}" =~ $conf ]]; then
sed -e "s|=| |" "$WORKDIR/$conf.conf" > "$WORKDIR/$conf.raw"
cp "$WORKDIR/$conf.raw" "/etc/smartdns.d/$conf.${SERVERS_GROUP[@]}.conf"
fi
done
echo "Restarting smartdns service..."
if hash systemctl 2>/dev/null; then
systemctl restart smartdns
elif hash service 2>/dev/null; then
service smartdns restart
elif hash rc-service 2>/dev/null; then
rc-service smartdns restart
elif hash busybox 2>/dev/null && [[ -d "/etc/init.d" ]]; then
/etc/init.d/smartdns restart
else
echo "Now please restart smartdns since I don't know how to do it."
fi
echo "Cleaning up..."
rm -r "$WORKDIR"