-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-hosts.sh
More file actions
executable file
·40 lines (29 loc) · 1.38 KB
/
update-hosts.sh
File metadata and controls
executable file
·40 lines (29 loc) · 1.38 KB
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
#!/bin/bash
rootcheck() {
if [[ $UID -ne 0 ]]; then
echo "Please run this script as root"
exit 1
fi
}
rootcheck
temphosts1=$(mktemp)
temphosts2=$(mktemp)
wget -nv -O - http://someonewhocares.org/hosts/hosts >> $temphosts1
wget -nv -O - http://winhelp2002.mvps.org/hosts.txt >> $temphosts1
wget -nv -O - http://www.malwaredomainlist.com/hostslist/hosts.txt >> $temphosts1
wget -nv -O - http://adblock.gjtech.net/?format=hostfile >> $temphosts1
wget -nv -O - http://hosts-file.net/ad_servers.asp >> $temphosts1
wget -nv -O - "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" >> $temphosts1
# This part gets pretty nasty :/
cp $temphosts1 $temphosts2
sed -e 's/\r//' -e '/^127.0.0.1/!d' -e '/localhost/d' -e 's/127.0.0.1/0.0.0.0/' -e 's/ \+/\t/' -e 's/#.*$//' -e 's/[ \t]*$//' < $temphosts1 | sort -u > temp1
sed -e 's/\r//' -e '/^127.0.0.1/!d' -e '/localhost/d' -e 's/127.0.0.1/::1/' -e 's/ \+/\t/' -e 's/#.*$//' -e 's/[ \t]*$//' < $temphosts2 | sort -u > temp2
cat temp1 temp2 >> /etc/hosts
rm $temphosts1 $temphosts2 temp1 temp2
sed -i '/127.0.0.1 localhost/d' /etc/hosts
sed -i '/::1 localhost/d' /etc/hosts
echo "127.0.0.1 $HOSTNAME
::1 $HOSTNAME" | cat - /etc/hosts >> temp && mv temp /etc/hosts
sudo ./ignore.sh
sed -i '/# Last updated on /d' /etc/hosts
echo "# Last updated on $(date)" | cat - /etc/hosts >> temp && mv temp /etc/hosts