# Adaway4linux by wb9688
# github.com/wb9688/Adaway4linux
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root!" 1>&2
exit 1
fi
echo "========================"
echo " Downloading files... "
echo "========================"
echo
curl "https://adaway.org/hosts.txt" > hosts1.txt
curl "http://winhelp2002.mvps.org/hosts.txt" > hosts2.txt
curl "http://hosts-file.net/ad_servers.txt" > hosts3.txt
curl "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintex"t > hosts4.txt
echo
echo "===================="
echo " Merging files... "
echo "===================="
cat hosts1.txt hosts2.txt hosts3.txt hosts4.txt exceptions.txt >> hosts
rm hosts1.txt hosts2.txt hosts3.txt hosts4.txt
sed '/^\#/d' hosts > hosts.tmp
mv hosts.tmp hosts
sed '/^$/d' hosts > hosts.tmp
mv hosts.tmp hosts
sed '/127.0.0.1 localhost/d' hosts > hosts.tmp
mv hosts.tmp hosts
sed '/::1 localhost/d' hosts > hosts.tmp
mv hosts.tmp hosts
sed '/127.0.0.1 localhost/d' hosts > hosts.tmp
mv hosts.tmp hosts
sed '/::1 localhost/d' hosts > hosts.tmp
mv hosts.tmp hosts
sed '/adf\.ly/d' hosts > hosts.tmp
mv hosts.tmp hosts
echo "# This file is automatically generated by Adaway4linux by wb9688" >> hosts_license
echo "# If you run Adaway4linux again this file will be overwritten" >> hosts_license
echo "# # Please add extra lines in a file called extra_lines.txt in the same directory as Adaway4linux" >> hosts_license
echo >> hosts_license
mv hosts hosts.txt
echo
echo "====================================="
echo " Backing up your old hosts file... "
echo "====================================="
if [ -f /etc/hosts.bkup ];
then
cat /etc/hosts.bkup > old_hosts
else
cp /etc/hosts /etc/hosts.bkup
cat /etc/hosts.bkup > old_hosts
fi
echo
echo "=========================================="
echo " Including old hosts file in new one... "
echo "=========================================="
cat hosts_license >> new_hosts
sed '/^\#/d' old_hosts > hosts.tmp
rm old_hosts
mv hosts.tmp old_hosts
cat old_hosts >> new_hosts
echo >> new_hosts
cat hosts.txt >> new_hosts
rm hosts_license
rm hosts.txt
mv new_hosts hosts
echo
echo "================================"
echo " Installing new hosts file... "
echo "================================"
cp hosts /etc/hosts
rm hosts
echo
echo "============="
echo " Finished! "
echo "============="