Last active
November 15, 2020 05:48
-
-
Save flinhong/2b5e286e5cd4bd96f4bf3383f904173d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# change directory to where the script resides | |
BASEDIR=$(dirname -- "$0") | |
cd "$BASEDIR" | |
rawURL="https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf" | |
rawfile="rawfile.conf" | |
upstream="upstream.conf" | |
dnspod="tls:\/\/dns.pub" | |
defaults=("tls://9.9.9.9" "tls://dns.google" "tls://1.1.1.1" "tls://public.dns.iij.jp" "tls://jp.tiar.app") | |
if [ -f "$rawfile" ] | |
then | |
filesize=$(wc -c < "$rawfile") | |
filesize=$(($filesize)) # parseInt | |
actualsize="$(curl -s -L -I $rawURL | awk 'tolower ($1) ~ /^content-length/ { print $2 }')" | |
actualsize=$(echo $actualsize | sed "s/$(printf '\r')\$//") # remove carriage return | |
if [ "$filesize" -ne "$actualsize" ] | |
then | |
echo "curl updated file" | |
curl -s $rawURL > $rawfile | |
fi | |
else | |
echo "curl updated file" | |
curl -s $rawURL > $rawfile | |
fi | |
sed 's/server=/[/g' $rawfile > $rawfile.temp | |
sed "s/114.114.114.114/]$dnspod/g" $rawfile.temp > $upstream | |
rm $rawfile.temp | |
for i in ${!defaults[@]}; | |
do | |
# echo ${defaults[$i]} | |
{ echo -e "${defaults[$i]}"; cat $upstream; } > $upstream.temp | |
mv $upstream{.temp,} | |
done | |
echo "done" | |
# in AdGuardHome.yaml, configure 'upstream_dns_file' to the path of the 'upstream.conf' that generated by this script | |
# sudo systemctl restart AdGuardHome.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment