This commit is contained in:
yinjiaji 2024-09-01 23:00:36 -04:00 committed by GitHub
commit e75eb4ae04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 4 deletions

View File

@ -1,7 +1,16 @@
#!/bin/bash #!/bin/bash
set -e set -e
SEDI=(-i)
DEFAULTCONFDIR="/etc/dnsmasq.d"
case "$(uname)" in
Darwin*)
DEFAULTCONFDIR="/opt/homebrew/etc/dnsmasq.d"
SEDI=(-i "")
esac
WORKDIR="$(mktemp -d)" WORKDIR="$(mktemp -d)"
CONFDIR=${1:-$DEFAULTCONFDIR}
SERVERS=(114.114.114.114 114.114.115.115 223.5.5.5 119.29.29.29) SERVERS=(114.114.114.114 114.114.115.115 223.5.5.5 119.29.29.29)
# 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
@ -10,6 +19,7 @@ SERVERS=(114.114.114.114 114.114.115.115 223.5.5.5 119.29.29.29)
CONF_WITH_SERVERS=(accelerated-domains.china google.china apple.china) CONF_WITH_SERVERS=(accelerated-domains.china google.china apple.china)
CONF_SIMPLE=(bogus-nxdomain.china) CONF_SIMPLE=(bogus-nxdomain.china)
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"
#git clone --depth=1 https://pagure.io/dnsmasq-china-list.git "$WORKDIR" #git clone --depth=1 https://pagure.io/dnsmasq-china-list.git "$WORKDIR"
@ -22,20 +32,20 @@ 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_SIMPLE[@]}"; do for _conf in "${CONF_WITH_SERVERS[@]}" "${CONF_SIMPLE[@]}"; do
rm -f /etc/dnsmasq.d/"$_conf"*.conf rm -f "$CONFDIR"/"$_conf"*.conf
done done
echo "Installing new configurations..." echo "Installing new configurations..."
for _conf in "${CONF_SIMPLE[@]}"; do for _conf in "${CONF_SIMPLE[@]}"; do
cp "$WORKDIR/$_conf.conf" "/etc/dnsmasq.d/$_conf.conf" cp "$WORKDIR/$_conf.conf" "$CONFDIR/$_conf.conf"
done done
for _server in "${SERVERS[@]}"; do for _server in "${SERVERS[@]}"; do
for _conf in "${CONF_WITH_SERVERS[@]}"; do for _conf in "${CONF_WITH_SERVERS[@]}"; do
cp "$WORKDIR/$_conf.conf" "/etc/dnsmasq.d/$_conf.$_server.conf" cp "$WORKDIR/$_conf.conf" "$CONFDIR/$_conf.$_server.conf"
done done
sed -i "s|^\(server.*\)/[^/]*$|\1/$_server|" /etc/dnsmasq.d/*."$_server".conf sed "${SEDI[@]}" "s|^\(server.*\)/[^/]*$|\1/$_server|" $CONFDIR/*."$_server".conf
done done
echo "Restarting dnsmasq service..." echo "Restarting dnsmasq service..."
@ -47,6 +57,8 @@ elif hash rc-service 2>/dev/null; then
rc-service dnsmasq restart rc-service dnsmasq restart
elif hash busybox 2>/dev/null && [[ -d "/etc/init.d" ]]; then elif hash busybox 2>/dev/null && [[ -d "/etc/init.d" ]]; then
/etc/init.d/dnsmasq restart /etc/init.d/dnsmasq restart
elif hash brew 2>/dev/null; then
brew services restart dnsmasq
else else
echo "Now please restart dnsmasq since I don't know how to do it." echo "Now please restart dnsmasq since I don't know how to do it."
fi fi