45 lines
1.6 KiB
Bash
45 lines
1.6 KiB
Bash
|
#!/bin/bash
|
||
|
set -e -o pipefail
|
||
|
|
||
|
tdir=$(mktemp -d -p /tmp update_list.XXXX)
|
||
|
echo $tdir |grep -Eq '^/tmp/update_list' || exit 1
|
||
|
cd $tdir
|
||
|
|
||
|
CHNROUTE=/etc/dnsmasq.d/chinadns_chnroute.txt
|
||
|
CHNROUTE6=/etc/dnsmasq.d/chinadns_chnroute6.txt
|
||
|
DNSMASQ=/etc/dnsmasq.d/dnsmasq_gfwlist.conf
|
||
|
DNS_IP=127.0.0.1
|
||
|
DNS_PORT=5453
|
||
|
CURL_OPT='--user-agent curl/8.1.2'
|
||
|
|
||
|
#CHNROUTE
|
||
|
FILE_CHNROUTE=$(basename $CHNROUTE)
|
||
|
FILE_CHNROUTE6=$(basename $CHNROUTE6)
|
||
|
curl $CURL_OPT https://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest -o delegated-apnic-latest.txt
|
||
|
cat delegated-apnic-latest.txt | grep ipv4 | grep CN | awk -F\| '{printf("%s/%d\n", $4, 32-log($5)/log(2))}' >> $FILE_CHNROUTE
|
||
|
cat delegated-apnic-latest.txt | grep ipv6 | grep CN | awk -F\| '{printf("%s/%d\n", $4, $5)}' >> $FILE_CHNROUTE6
|
||
|
rm delegated-apnic-latest.txt
|
||
|
|
||
|
#GFWLIST
|
||
|
FILE_DNSMASQ=$(basename $DNSMASQ)
|
||
|
git clone https://github.com/felixonmars/dnsmasq-china-list.git --depth=1
|
||
|
pushd dnsmasq-china-list
|
||
|
make SERVER='#' dnsmasq
|
||
|
cat accelerated-domains.china.dnsmasq.conf google.china.dnsmasq.conf apple.china.dnsmasq.conf > $FILE_DNSMASQ
|
||
|
|
||
|
curl $CURL_OPT https://publicsuffix.org/list/public_suffix_list.dat |python3 -c "
|
||
|
r=[l.split('/')[1] for l in open('${FILE_DNSMASQ}').read().split('\n') if l.strip()]
|
||
|
d=sorted(list({l.strip().split('.')[-1].encode('idna').decode('utf-8') for l in open(0) if l.strip() and not l.startswith('//')}))
|
||
|
d=['server=/'+i+'/${DNS_IP}#${DNS_PORT}' for i in d if i not in r]
|
||
|
print('\n')
|
||
|
print('\n'.join(d))
|
||
|
" >> $FILE_DNSMASQ
|
||
|
|
||
|
mv -f ../$FILE_CHNROUTE $CHNROUTE
|
||
|
mv -f ../$FILE_CHNROUTE6 $CHNROUTE6
|
||
|
mv -f ./$FILE_DNSMASQ $DNSMASQ
|
||
|
popd
|
||
|
|
||
|
cd /
|
||
|
rm -rf $tdir
|