#!/bin/bash
#                       /usr/local/bin/etc_hosts
# https://crystalfaeries.net/posix/bin/etc_hosts
# celeste:crystalfaery ETC_HOSTS 2017-08-17 02:41:00+00:00
# LICENSE: PUBLIC DOMAIN
# Original Author: Aaron Toponce
# Original Date: Apr 08, 2013
# Original License: None. Released to the public domain
# NOTE: the contents of this file MUST be edited by you
# to reflect your configuration, as this is very customized!
# The ultimate output file from running this is			/etc/hosts.tmp
# which should be manually reviewed before installing as	/etc/hosts

if [ $# -ne 0 ]
then	# catch any version of -h --help -v --version
	head -n 12 $0
	exit 0	# hope that helped...
else

FILE1="/tmp/hosts.tmp1"
FILE2="/tmp/hosts.tmp2"

curl -so "${FILE1}" -G -d hostformat=hosts -d showintro=0 -d mimetype=plaintext 'http://pgl.yoyo.org/adservers/serverlist.php'
curl -s 'https://hosts-file.net/.%5Cad_servers.txt' >>	"${FILE1}"
curl -s 'http://winhelp2002.mvps.org/hosts.txt'	>>	"${FILE1}"
sed -i 's/^127.0.0.1/0.0.0.0/'				"${FILE1}"
awk '(NF){sub(/\#.*/,"")}; (NF){sub(/\r$/,""); $1=$1; print}' "${FILE1}" | sort -u > "${FILE2}"
sed -i '$d' "${FILE2}"

echo -n '# /etc/hosts for crystalfaeries.net '	>  /etc/hosts.tmp
/usr/local/bin/now				>> /etc/hosts.tmp
cat						>> /etc/hosts.tmp << EOF

# DO NOT EDIT THIS FILE, INSTEAD EDIT: /usr/local/bin/etc_hosts

####### ####### #######	LOCALHOST	####### ####### #######
#	Local Aliases REQUIRED TO EXIST:
127.0.0.1	ip4-localhost	localhost
127.0.0.1	ip4-loopback	loopback
::1		ip6-localhost	ip6-loopback
#::1  localhost	ip6-localhost	ip6-loopback
fe00::0		ip6-localnet
# fe80::1%lo0	localhost
ff00::0		ip6-mcastprefix
ff02::1		ip6-allnodes
ff02::2		ip6-allrouters
ff02::3		ip6-allhosts
255.255.255.255	broadcasthost

####### ####### #######	WAN	####### ####### #######
# DNS:
208.67.222.222	resolver1.opendns.com
208.67.220.220	resolver2.opendns.com
# My IP address:
EOF
echo -n "$(/usr/local/bin/myip)"\
						>> /etc/hosts.tmp
echo "   $(host `myip` | sed 's/^.* //g')"	>> /etc/hosts.tmp
cat						>> /etc/hosts.tmp << EOF

####### ####### #######	LAN	####### ####### #######
# RFC 1918 + RFC 6598:
#       fc00::/7	IPv6 Unique Local Addresses
#     10.0.0.0/8	(   10.0.0.0	- 10.255.255.255)
#  100.64.0.0/10	( 100.64.0.0	-100.127.255.255)
#  172.16.0.0/12	( 172.16.0.0	- 172.31.255.255)
# 192.168.0.0/16	(192.168.0.0	-192.168.255.255)
# My IP address:
EOF
echo -n "$(/sbin/ifconfig wlan0 | grep "inet " | sed 's/^.* inet //g;s/ .*$//g')"\
						>> /etc/hosts.tmp
echo "   $(hostname -f)	$(hostname -s)"		>> /etc/hosts.tmp
cat						>> /etc/hosts.tmp << EOF

############################################################
# THE FOLLOWING LINES ARE TO BLOCK ADVERTISING AND MALWARE #
############################################################

# For being a CIA front:
0.0.0.0 facebook.com
0.0.0.0 www.facebook.com

# For supporting involuntary servitude:
0.0.0.0 splcenter.org
0.0.0.0 www.splcenter.org

# For invasive tracking
0.0.0.0 cordial.io
0.0.0.0 pingdom.com
0.0.0.0 pingdom.net

# For just being assholes
0.0.0.0	scribd.com
0.0.0.0	www.scribd.com

# Block Lists agregated by $0:
$(cat "${FILE2}")

EOF
rm "${FILE1}" "${FILE2}"
fi


syntax highlighted by Code2HTML, v. 0.9.1