/
update_addomains.sh
executable file
·156 lines (111 loc) · 3.84 KB
/
update_addomains.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
#
# Update the ads domain list
#
# This script really needs tidying/refactoring
function blockdomain(){
domain=$1
echo "$domain" >> blockeddomains.build.txt
# Check if the domain exists within a zone that'll be blocked
egrep -v -e "^${domain#*.}|^$domain" autolist.zones.txt > /dev/null
if [ "$?" == "1" ]
then
cat << EOM >> autolist.build.txt
local-data: "$domain A 127.0.0.1"
local-data: "$domain IN AAAA ::1"
EOM
fi
}
cd "$1"
wget -O autolist.tmp.txt "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=unbound;showintro=0&mimetype=plaintext"
wget -O minerdomains.txt https://raw.githubusercontent.com/Marfjeh/coinhive-block/master/domains
wget -O xiaomidomains.txt https://gist.githubusercontent.com/unknownFalleN/3f38e2daa8a98caff1b0d965c2b89b25/raw
# Added in ADBLK-27
if [ ! -d cname-trackers ]
then
git clone https://github.com/AdguardTeam/cname-trackers
else
cd cname-trackers
git pull
cd ..
fi
# TODO - should move excludes into a dedicated file, but setting this up in a hurry
sed -i 's/player.h-cdn.com/#player.h-cdn.com/g' minerdomains.txt
# Strip names out of the autolist so we can process and remove duplicates
grep "local-zone" autolist.tmp.txt | cut -d\ -f2 | sed 's/"//g' > autolist.doms.txt
# Start compiling the autolist
cat minerdomains.txt | egrep -v -e '^#|^$' | sed 's/igrid.org\^/igrid.org/' | while read -r domain
do
echo "$domain" >> autolist.doms.txt
done
cat xiaomidomains.txt | egrep -v -e '^#' | while read -r domain
do
echo "$domain" >> autolist.doms.txt
done
# Iterate over the manualblocks
for blockfile in config/manualblocks/*txt
do
cat $blockfile | egrep -v -e '^#' | while read -r domain
do
echo "$domain" >> autolist.doms.txt
done
done
# Truncate the existing file
> autolist.zones.txt
# Iterate over the zones and start compiling the zone blocker
cat config/manualzones.txt | egrep -v -e '^#' | while read -r domain
do
echo "$domain" >> autolist.zones.txt
done
# Check for any domains blocked in manualpages (i.e. no variables and no path specified)
egrep -v -e '/|\$' config/manualpages.txt | egrep -v -e '^#' | sed 's/www\.//g' | while read -r domain
do
echo "$domain" >> autolist.zones.txt
done
# Finally process the list, and use it to build the new autolist
> blockeddomains.build.txt
cat autolist.doms.txt | sort | uniq | egrep -v -e '^$' | while read -r domain
do
blockdomain $domain
done
# ADBLK-27 process CNAME tracker domains and add them to the blocked domains list
for f in `find ./cname-trackers/trackers -name '*.txt'`
do
grep '||' $f | tr -d '^|' | while read -r domain
do
blockdomain $domain
done
done
# Block the various zones
> zoneblocks.unbound.txt
> blockedzones.txt
cat autolist.zones.txt | sort | uniq | egrep -v -e '^$' | while read -r domain
do
cat << EOM >> autolist.build.txt
local-zone: "$domain" redirect
local-data: "$domain A 127.0.0.1"
EOM
cat << EOM >> zoneblocks.unbound.txt
local-zone: "$domain" redirect
local-data: "$domain A 127.0.0.1"
EOM
echo "$domain" >> blockedzones.txt
done
mv autolist.build.txt autolist.txt
cat blockeddomains.build.txt | sort | uniq > blockeddomains.build.1.txt
mv blockeddomains.build.1.txt blockeddomains.txt
rm -f blockeddomains.build.txt
# Check for any domains blocked in the social media list
> blocked_domains_with_sm.build.txt
egrep -v -e '/|\$' config/social_media_trackers.txt | egrep -v -e '^#' | sed 's/www\.//g' | while read -r domain
do
echo "$domain" >> blocked_domains_with_sm.build.txt
done
cat blockeddomains.txt >> blocked_domains_with_sm.build.txt
mv blocked_domains_with_sm.build.txt blocked_domains_with_sm.txt
# ADBLK-21: Publish the Regex List
cat config/regexes/*txt | sort | uniq > regex_blocks.tmp
mv regex_blocks.tmp regex_blocks.txt
# Tidy up
rm -f autolist.zones.txt autolist.doms.txt autolist.tmp.txt blockeddomains.build.txt
"$1/bin/build_abp.sh"