-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-whitelist.sh
36 lines (28 loc) · 1.25 KB
/
update-whitelist.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
#!/bin/bash
echo -e "This script will download and update domains into the DNS whitelist zone."
sleep 0.1
if [ "$(id -u)" != "0" ] ; then
echo "This script requires root permissions. Please run this as root!"
exit 2
fi
echo "Downloading updated whitelist..."
curl -# -L "https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt" \
| sed 's/$/ CNAME rpz-passthru./g' > /tmp/whitelist.list
echo "Merging with the current database..."
cp /etc/bind/db.rpz.whitelist /tmp/current.list
cat /tmp/whitelist.list | tee -a /tmp/current.list > /dev/null
cat /tmp/current.list \
| tail -n+3 \
| sort \
| uniq --ignore-case > /tmp/updated.list
echo "Updating zone serial..."
awk '{ if ( $0 ~ /[\t ]SOA[\t ]/ ) $7=$7+1; print}' /usr/local/bin/whitelist-zone.header > /usr/local/bin/whitelist-zone.header.new
mv /usr/local/bin/whitelist-zone.header.new /usr/local/bin/whitelist-zone.header
cp /usr/local/bin/whitelist-zone.header /etc/bind/db.rpz.whitelist
cat /tmp/updated.list | tee -a /etc/bind/zones/db.rpz.whitelist > /dev/null
echo "Echo checking if bind9 configuration has been broken..."
named-checkconf
echo "Cleaning up..."
rm /tmp/*.list
echo "Done!"
echo "Use 'rndc reload' command to reload the zone."