mirror of
https://gitee.com/callmer/pve_toss_notes.git
synced 2026-08-31 14:02:53 +08:00
更新 SmartDNS 插件脚本
This commit is contained in:
@@ -1,22 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
WORKDIR="$(mktemp -d)"
|
WORKDIR="$(mktemp -d)"
|
||||||
CONFDIR="/etc/smartdns.d"
|
CONFDIR="/etc/smartdns.d"
|
||||||
SERVERS=(223.5.5.5 180.184.1.1 119.29.29.29 114.114.114.114 2402:4e00:: 2400:3200::1)
|
SERVERS="223.5.5.5 180.184.1.1 119.29.29.29 114.114.114.114 2402:4e00:: 2400:3200::1"
|
||||||
GROUP=(flash)
|
GROUP="flash"
|
||||||
# Others: 223.6.6.6 119.28.28.28
|
# Others: 223.6.6.6 119.28.28.28
|
||||||
# Not using best possible CDN pop: 1.2.4.8 210.2.4.8
|
# Not using best possible CDN pop: 1.2.4.8 210.2.4.8
|
||||||
# Broken?: 180.76.76.76
|
# Broken?: 180.76.76.76
|
||||||
|
|
||||||
CONF_WITH_SERVERS=(accelerated-domains.china google.china apple.china)
|
CONF_WITH_SERVERS="accelerated-domains.china google.china apple.china"
|
||||||
CONF_WITH_GROUP=(dns-group.china)
|
CONF_WITH_GROUP="dns-group.china"
|
||||||
CONF_SIMPLE=(bogus-nxdomain.china)
|
CONF_SIMPLE="bogus-nxdomain.china"
|
||||||
|
|
||||||
echo "Checking whether the configuration folder exists..."
|
echo "Checking whether the configuration folder exists..."
|
||||||
if [ ! -d "$CONFDIR" ]; then
|
[ -d "$CONFDIR" ] || mkdir -p "$CONFDIR"
|
||||||
mkdir -p "$CONFDIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
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"
|
||||||
@@ -25,43 +23,52 @@ git clone --depth=1 https://gitee.com/felixonmars/dnsmasq-china-list.git "$WORKD
|
|||||||
#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"
|
||||||
#git clone --depth=1 https://gitlab.com/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://e.coding.net/felixonmars/dnsmasq-china-list.git "$WORKDIR"
|
||||||
|
#git clone --depth=1 https://atomgit.com/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 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"
|
#git clone --depth=1 http://repo.or.cz/dnsmasq-china-list.git "$WORKDIR"
|
||||||
|
|
||||||
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
|
||||||
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\\/${GROUP[@]}/p" "$WORKDIR/$_conf.step1.raw" > "$WORKDIR/$_conf.step2.raw"
|
|
||||||
cp "$WORKDIR/$_conf.step2.raw" "$CONFDIR/$_conf.smartdns.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${CONF_WITH_GROUP[@]}" =~ $_conf ]]; then
|
case "$CONF_WITH_SERVERS" in
|
||||||
for _server in "${SERVERS[@]}"; do
|
*"$_conf"*)
|
||||||
echo "server $_server -group ${GROUP[@]} -exclude-default-group" >> "$WORKDIR/$_conf.raw"
|
sed -n 's/^server=\/\([^\/]*\)\/114.114.114.114$/\1/p' "$WORKDIR/$_conf.conf" | grep -v '^#' > "$WORKDIR/$_conf.step1.raw"
|
||||||
done
|
sed -e "s/.*/nameserver \/&\/$GROUP/" "$WORKDIR/$_conf.step1.raw" > "$WORKDIR/$_conf.step2.raw"
|
||||||
cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.smartdns.conf"
|
cp "$WORKDIR/$_conf.step2.raw" "$CONFDIR/$_conf.smartdns.conf"
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
case "$CONF_SIMPLE" in
|
||||||
|
*"$_conf"*)
|
||||||
|
sed -e "s/=/ /" "$WORKDIR/$_conf.conf" > "$WORKDIR/$_conf.raw"
|
||||||
|
cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.smartdns.conf"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
if [[ "${CONF_SIMPLE[@]}" =~ $_conf ]]; then
|
|
||||||
sed -e "s|=| |" "$WORKDIR/$_conf.conf" > "$WORKDIR/$_conf.raw"
|
|
||||||
cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.smartdns.conf"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Restarting smartdns service..."
|
echo "Restarting smartdns service..."
|
||||||
if hash systemctl 2>/dev/null; then
|
if command -v systemctl >/dev/null 2>&1; then
|
||||||
systemctl restart smartdns
|
systemctl restart smartdns
|
||||||
elif hash service 2>/dev/null; then
|
elif command -v service >/dev/null 2>&1; then
|
||||||
service smartdns restart
|
service smartdns restart
|
||||||
elif hash rc-service 2>/dev/null; then
|
elif command -v rc-service >/dev/null 2>&1; then
|
||||||
rc-service smartdns restart
|
rc-service smartdns restart
|
||||||
elif hash busybox 2>/dev/null && [[ -d "/etc/init.d" ]]; then
|
elif command -v busybox >/dev/null 2>&1 && [ -d "/etc/init.d" ]; 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 since I don't know how to do it."
|
||||||
|
|||||||
Reference in New Issue
Block a user