Skip to content

Instantly share code, notes, and snippets.

@crazygit
Last active February 17, 2020 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazygit/1e16da4bcfcb4936242fe2183b8a6295 to your computer and use it in GitHub Desktop.
Save crazygit/1e16da4bcfcb4936242fe2183b8a6295 to your computer and use it in GitHub Desktop.
Install dnsmasq-china-list on macos
#!/bin/bash
set -e
# install dnsmasq
brew install dnsmasq
WORKDIR="$(mktemp -d)"
SERVERS=(114.114.114.114 114.114.115.115 180.76.76.76)
# Not using best possible CDN pop: 1.2.4.8 210.2.4.8 223.5.5.5 223.6.6.6
# Dirty cache: 119.29.29.29 182.254.116.116
CONF_WITH_SERVERS=(accelerated-domains.china google.china apple.china)
CONF_SIMPLE=(bogus-nxdomain.china)
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://codehub.devcloud.huaweicloud.com/dnsmasq-china-list00001/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 https://code.aliyun.com/felixonmars/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_SIMPLE[@]}"; do
rm -f /usr/local/etc/dnsmasq.d/"$_conf"*.conf
done
echo "Installing new configurations..."
for _conf in "${CONF_SIMPLE[@]}"; do
cp "$WORKDIR/$_conf.conf" "/usr/local/etc/dnsmasq.d/$_conf.conf"
done
mkdir -p /usr/local/etc/dnsmasq.d/
for _server in "${SERVERS[@]}"; do
for _conf in "${CONF_WITH_SERVERS[@]}"; do
cp "$WORKDIR/$_conf.conf" "/usr/local/etc/dnsmasq.d/$_conf.$_server.conf"
done
sed -i "s|^\(server.*\)/[^/]*$|\1/$_server|" /usr/local/etc/dnsmasq.d/*."$_server".conf
done
echo "Restarting dnsmasq service..."
brew services start dnsmasq
echo "Cleaning up..."
rm -r "$WORKDIR"
@crazygit
Copy link
Author

crazygit commented Feb 17, 2020

不要忘记在/usr/local/etc/dnsmasq.conf文件中启用配置

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment