#!/bin/bash
#                       /usr/local/bin/etc_hosts
# https://crystalfaeries.net/posix/bin/etc_hosts
# celeste:crystalfaery ETC_HOSTS 2021-04-28 16:59:50+00:00
# 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+
# which should be manually reviewed before installing as	/etc/hosts
# as it would be insane to blindly trust the downloaded files.

let help=13	# line # within file - 1

if [ $# -ne 0 ]
then	# catch any version of -h --help -v --version
	head -n $help $0
	exit $?	# hope that helped...
else	# it's the real deal, do our job:

# prepare our target file:
umask	0002
touch		/etc/hosts+	2>/dev/null	||	sudo touch		/etc/hosts+
chmod 664	/etc/hosts+	2>/dev/null	||	sudo chmod 664		/etc/hosts+
chgrp staff	/etc/hosts+	2>/dev/null	||	sudo chgrp staff	/etc/hosts+

# temporary working space:
FILE1="/tmp/hosts.$$.tmp1"
FILE2="/tmp/hosts.$$.tmp2"

# download the public list(s)
curl -so "${FILE1}" -G -d hostformat=hosts -d showintro=0 -d mimetype=plaintext 'https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&amp;showintro=0&amp;mimetype=plaintext'
awk   '(NF){sub(/#.*/,"")}; (NF){sub(/\r$/,""); $1=$1; print}' "${FILE1}" | sort -u > "${FILE2}"	# seems to work
#awk '(NF){sub(/\#.*/,"")}; (NF){sub(/\r$/,""); $1=$1; print}' "${FILE1}" | sort -u > "${FILE2}"	# does this work?
rm	"${FILE1}"	# clean up

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

####### ####### #######	DANGER!	DANGER WILL ROBINSON!	####### ####### #######
# DO NOT EDIT:               /etc/hosts{-,,+}
#INSTEAD EDIT: /usr/local/bin/etc_hosts
# then run the script
# then verify		/etc/hosts+
# then mv /etc/hosts	/etc/hosts-
# then cp /etc/hosts+	/etc/hosts
# then cp /dev/null	/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
127.0.0.1	fey.crystalfaeries.net	fey

####### ####### #######	DNS	####### ####### #######
1.1.1.1		one.one.one.one
208.67.222.222	resolver1.opendns.com
208.67.220.220	resolver2.opendns.com

####### ####### #######	WAN	####### ####### #######
# crystalfaeries.net Web+E-Mail server:
216.172.168.52	box6003.bluehost.com	# server
216.172.168.52	www.crystalfaeries.net	# server

# HOTSPOT ADDRESS to share via hotspotd
10.42.0.1	crystalfaeries.net
10.42.0.1	haleohana.net
10.42.0.1	kauaicamping.com

EOF

#echo -n "$(/usr/local/bin/myip)"		>> /etc/hosts+
#echo "   $(host `myip` | sed 's/^.* //g')"	>> /etc/hosts+
#echo -n "$(/sbin/ifconfig wlan0 | grep "inet " | sed 's/^.* inet //g;s/ .*$//g')"	>> /etc/hosts+
#echo -n "$(/sbin/ifconfig wlp11s0 | grep "inet " | sed 's/^.* inet //g;s/ .*$//g')"	>> /etc/hosts+
#echo -n "127.0.1.1	"			>> /etc/hosts+
#echo "$(hostname -f)	$(hostname -s)"		>> /etc/hosts+

cat						>> /etc/hosts+ << EOF

####### ####### #######	LAN	####### ####### #######
# RFC 1918 + RFC 6598:
#       fc00::/7	IPv4 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)

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

# For misleading spiritual teachings (resistance = negative synergy)
127.0.0.1 2012portal.blogspot.com
127.0.0.1 www.2012portal.blogspot.com

# For being an AI front:
127.0.0.1 collective-evolution.com
127.0.0.1 www.collective-evolution.com

# For being a CIA front:
127.0.0.1 encrypted.google.com
127.0.0.1 facebook.com
127.0.0.1 m.facebook.com
127.0.0.1 www.facebook.com
127.0.0.1 google.com
127.0.0.1 m.google.com
127.0.0.1 www.google.com
127.0.0.1 googleusercontent.com
127.0.0.1 www.googleusercontent.com
127.0.0.1 ci0.googleusercontent.com
127.0.0.1 ci1.googleusercontent.com
127.0.0.1 ci2.googleusercontent.com
127.0.0.1 ci3.googleusercontent.com
127.0.0.1 ci4.googleusercontent.com
127.0.0.1 ci5.googleusercontent.com
127.0.0.1 ci6.googleusercontent.com
127.0.0.1 ci7.googleusercontent.com
127.0.0.1 ci8.googleusercontent.com
127.0.0.1 ci9.googleusercontent.com
127.0.0.1 lh0.googleusercontent.com
127.0.0.1 lh1.googleusercontent.com
127.0.0.1 lh2.googleusercontent.com
127.0.0.1 lh3.googleusercontent.com
127.0.0.1 lh4.googleusercontent.com
127.0.0.1 lh5.googleusercontent.com
127.0.0.1 lh6.googleusercontent.com
127.0.0.1 lh7.googleusercontent.com
127.0.0.1 lh8.googleusercontent.com
127.0.0.1 lh9.googleusercontent.com
127.0.0.1 themes.googleusercontent.com

# For invasive tracking
127.0.0.1 cordial.io
127.0.0.1 gaiaportal.wordpress.com
127.0.0.1 lisnr.com
127.0.0.1 pingdom.com
127.0.0.1 pingdom.net
127.0.0.1 www.cordial.io
127.0.0.1 www.lisnr.com
127.0.0.1 www.pingdom.com
127.0.0.1 www.pingdom.net

# For invasive advertising
127.0.0.1 consciouslifenews.com
127.0.0.1 www.consciouslifenews.com

# For supporting involuntary servitude:
127.0.0.1 cornell.edu
127.0.0.1 law.cornell.edu
127.0.0.1 splcenter.org
127.0.0.1 www.cornell.edu
127.0.0.1 www.splcenter.org

# For requiring JavaScript
127.0.0.1 uamntv.ru-clip.net

# For Requiring Subscription to E-Mail
127.0.0.1	articles.mercola.com
127.0.0.1	www.mercola.com
127.0.0.1	mercola.com

# For blocking downloads (e.g. StreamRipper)
127.0.0.1 fccdl.in
127.0.0.1 freeconferencecall.com
127.0.0.1 livecast365.com
127.0.0.1 pinterest.com
127.0.0.1 www.fccdl.in
127.0.0.1 www.freeconferencecall.com
127.0.0.1 www.pinterest.com

# For Digital Restrictions Management
127.0.0.1	apple.com
127.0.0.1	live365.com
127.0.0.1	music.apple.com
127.0.0.1	nationalfile.com
127.0.0.1	podcasts.apple.com
127.0.0.1	tunein.com
127.0.0.1	www.apple.com
127.0.0.1	www.live365.com
127.0.0.1	www.music.apple.com
127.0.0.1	www.nationalfile.com

# For Censorship
127.0.0.1	alternatemetaverse.com		# Cataplexia Numbers
127.0.0.1	t.co
127.0.0.1	twitter.com
127.0.0.1	www.twitter.com
127.0.0.1	www.alternatemetaverse.com	# Cataplexia Numbers

# For just being assholes
127.0.0.1	audienceinsights.net
127.0.0.1	behavioralengine.com
127.0.0.1	kauaiforward.com
127.0.0.1	scribd.com
127.0.0.1	static.audienceinsights.net
127.0.0.1	virtualitygrid.com
127.0.0.1	www.audienceinsights.net
127.0.0.1	www.behavioralengine.com
127.0.0.1	www.kauaiforward.com
127.0.0.1	www.scribd.com
127.0.0.1	www.virtualitygrid.com

# For being old paradigm (including supporting CoronaVirus SCAM)
127.0.0.1	ancient-origins.net
127.0.0.1	claremont.org
127.0.0.1	greenmedinfo.com
127.0.0.1	hubs.mozilla.com
127.0.0.1	kauai.gov
127.0.0.1	linuxfoundation.org 
127.0.0.1	matrixdisclosure.com
127.0.0.1	members.ancient-origins.net
127.0.0.1	mewe.com
127.0.0.1	monroeinstitute.org
127.0.0.1	national-assembly.net
127.0.0.1	naturalnews.com
127.0.0.1	nextgov.com
127.0.0.1	nytimes.com
127.0.0.1	occultopedia.com
127.0.0.1	slashdotmedia.com
127.0.0.1	techrights.org
127.0.0.1	www.ancient-origins.net
127.0.0.1	www.claremont.org
127.0.0.1	www.greenmedinfo.com
127.0.0.1	www.kauai.gov
127.0.0.1	www.linuxfoundation.org 
127.0.0.1	www.matrixdisclosure.com
127.0.0.1	www.mewe.com
127.0.0.1	www.monroeinstitute.org
127.0.0.1	www.national-assembly.net
127.0.0.1	www.naturalnews.com
127.0.0.1	www.nextgov.com
127.0.0.1	www.nytimes.com
127.0.0.1	www.occultopedia.com
127.0.0.1	www.slashdotmedia.com
127.0.0.1	www.techrights.org

# For being old domains release to site squatters:
127.0.0.1	inworldz.com
127.0.0.1	techrights.org
127.0.0.1	www.inworldz.com
127.0.0.1	www.techrights.org

# External Block Lists downloaded by $0:
EOF

cat	"${FILE2}" >> /etc/hosts+
rm	"${FILE2}"

touch		/etc/hosts+	2>/dev/null	||	sudo touch		/etc/hosts+
chmod 664	/etc/hosts+	2>/dev/null	||	sudo chmod 664		/etc/hosts+
chgrp staff	/etc/hosts+	2>/dev/null	||	sudo chgrp staff	/etc/hosts+
mv		/etc/hosts	/etc/hosts-	||	sudo mv	/etc/hosts	/etc/hosts-
cp		/etc/hosts+	/etc/hosts	||	sudo cp	/etc/hosts+	/etc/hosts
cp		/dev/null	/etc/hosts+	||	sudo cp /dev/null	/etc/hosts+
diff		/etc/hosts-	/etc/hosts	|	less -X
fi		# pau for now...
exit	$?	# how'd we do?
