This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
notracking_update
47 lines (42 loc) · 1.88 KB
/
notracking_update
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
#!/bin/bash
#
# ABOUT
# This is a simple autoupdate and whitelist script for the notracking blocklists.
# notracking lists: https://github.com/notracking/hosts-blocklists
# script source: https://github.com/notracking/hosts-blocklists-scripts
#
# HOWTO
# For Debian based systems
# - Install curl: sudo apt install curl
# - Download this file to: /etc/cron.daily/notracking_update
# - Mark it as executable: sudo chmod +x /etc/cron.daily/notracking_update
# - Update the CONFIG section in this script: sudo nano /etc/cron.daily/notracking_update
# - Do a test run: sudo /etc/cron.daily/notracking_update
#
# WHITELISTING
# Any line in the blocklist that contains one of the lines in the whitelist will be automatically removed.
# Only rules that include a dot '.' will be used to avoid simple mistakes.
#
######## CONFIG ########
listdir=/path/to/lists/directory
########################
echo -n "[+] Downloading notracking updates: "
curl --silent -o $listdir/hostnames.txt https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt
curl --silent -o $listdir/domains.txt https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt
echo "OK!"
echo -n "[+] Applying whitelist: "
touch $listdir/whitelist.txt # create empty whitelist in case it does not exist
while IFS= read -r line; do # IFS= to prevent read from remove leading or tailing spaces
if [[ $line == *"."* ]] # line must at least contain a '.' to avoid simple mistakes
then
line="${line%%[[:cntrl:]]}" # removes tailing newline
grep -v "${line}" $listdir/hostnames.txt > $listdir/hostnames.tmp.txt
grep -v "${line}" $listdir/domains.txt > $listdir/domains.tmp.txt
mv $listdir/hostnames.tmp.txt $listdir/hostnames.txt
mv $listdir/domains.tmp.txt $listdir/domains.txt
fi
done < $listdir/whitelist.txt
echo "OK!"
echo -n "[+] Restarting Dnsmasq: "
service dnsmasq restart
echo "OK!"