forked from gigibox/gfwlist2dnsmasq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfwlist2dnsmasq.sh
executable file
·96 lines (86 loc) · 2.11 KB
/
gfwlist2dnsmasq.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
#
# Update Time 2021.11.29 suzukua
# rm ipset too support clash dns
#
# Created Time: 2016.12.06 zhangzf
# Translate the gfwlist in base64 to dnsmasq rules with ipset
#
MYDNSIP=${2:-127.0.0.1}
MYDNSPORT=${3:-23453}
IPSETNAME=${4:-dnsmasq_gfw}
IPSETNAME6=${5:-dnsmasq_gfw6}
# GFWURL="https://ghproxy.com/https://raw.githubusercontent.com/Loukky/gfwlist-by-loukky/master/gfwlist.txt"
GFWURL="https://raw.githubusercontent.com/hezhijie0327/GFWList2AGH/main/gfwlist2domain/blacklist_full.txt"
GFWLIST_TMP_BASE64="/tmp/gfwlist.txt.base64"
GFWLIST_TMP="/home/runner/work/publish/gfw.conf"
# curl & base64 command path
CURL=$(which curl)
CURLOPT="-s -k -o $GFWLIST_TMP_BASE64"
# BASE64=$(which base64)
c_conf() {
echo "# Updated on:$(date '+%F %T')" > $GFWLIST_TMP
while read LINE; do
if [ "$(filter "$LINE")" -eq "0" ]; then
printf 'server=/.%s/%s#%s\n' $LINE $MYDNSIP $MYDNSPORT >> $GFWLIST_TMP
printf 'ipset=/.%s/%s,%s\n' $LINE $IPSETNAME $IPSETNAME6 >> $GFWLIST_TMP
fi
done
}
#排除某些规则
filter(){
rule="$1"
echo "$(echo "$rule" | grep -Ec "asuscomm\.com|asus\.com|dns\.google|m-team\.cc|eu\.org|^com\.")"
}
gen(){
echo "开始下载GFW规则,过程可能较慢,请耐心等待"
# download
if [ ! -f $GFWLIST_TMP_BASE64 ]; then
$CURL $CURLOPT $GFWURL
[ "$?" -eq 0 ] || {
echo "Gfwlist download failed."
exit 1
}
fi
# parse gfwlist
# $BASE64 -d $GFWLIST_TMP_BASE64 \
cat $GFWLIST_TMP_BASE64 \
| grep -v \
-e '^\s*$' \
-e '^[\[!@@]' \
-e '[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]' \
| sed \
-e s'/^[@|]*//'g \
-e s'/^http[s]*:\/\///'g \
-e s'/[\/\%].*$//'g \
-e s'/[^a-z]\+$//'g \
-e s'/.*\*[^\.]*//'g \
-e s'/^\.//'g 2>/dev/null \
| grep -e '\.' \
| sort -u \
| c_conf
rows=$(grep -c "$IPSETNAME" $GFWLIST_TMP)
sed -i "1i# Rows:${rows}" $GFWLIST_TMP
rm $GFWLIST_TMP_BASE64 -f
echo "更新GFW规则完毕"
}
#删除dns
del(){
#rm -rf $DNSMASQ_GFW
rm -rf $GFWLIST_TMP;
}
pwd
echo #################
ls -lah
command=$1
case $command in
(gen)
gen
;;
(del)
del
;;
(*)
echo "暂不支持该命令${command},只支持gen、del"
;;
esac