#!/bin/sh
# ~/public_html/bin/.sh/firefox-clean
# http://www.berklix.com/~jhs/bin/.sh/firefox-clean
# Installed to /site/usr/local/bin/firefox-clean
# by:
#	cd ~/public_html/bin/.sh ; make install
#	cd /site; xs make 2dell
#	ls -l /usr/local/bin/firefox-clean
#	ln -s /site/usr/local/bin/firefox-clean /usr/local/bin/firefox-clean

# Purpose:
# So you can happily accept all web sites junk cookies, then purge
# the whole lot as often as you like, including any that were not
# even declared, eg by criminals etc, before they can seriously build
# up & track you, Thus saving masses of time by not reading every
# damn web sites different policy on various cookies in perhaps
# foreign languages too, then deciding if you believe them, what
# legal jurisdiction & data protection restrictions they claim to
# be operating under, & which subset of their cookies you might or
# not accept, or wondering are they thieving liars out to harvest you,

# Maybe someone may have written a similar script for MS,
# but Ive not looked, if something similar exists we could cross link.

# JJLATER Remove internal host names

# JJLATER maybe incorporate http://addons.mozilla.org/en-US/firefox/addon/noscript/?utm_source=addons.mozilla.org&utm_medium=referral&utm_content=search

# Temporary hack to observe startup speed
echo "firefox-clean starting `date`" > ~/tmp/firefox-clean.date
# cat ~/tmp/firefox-clean.date
## echo >> ~/tmp/firefox-clean.log
## cat ~/tmp/firefox-clean.date >> ~/tmp/firefox-clean.log

# See Also:
#	http://www.berklix.com/~jhs/adverts/
#	~jhs/.fvwm/config
#
# This script was started 2014-04
# Written after I proved ( at http://www.berklix.com/~jhs/toytown/ )
# some companies were tracking & individually target advertising me
# (& of course all people), presumably using a combination of cookies,
# IP number, & exported environment.
# At 2020 I see near all spam in my ~/mail/spam/phrases/ is German.
# Yet vast majority of my ~/.procmailrc_phrases_src are English,
# Deduction:	most web sites tracking me are harvesting my German IP numbers

# This script not yet with much protection.

# JJLATER it would be better to invoke & run firefox from
# a sand box or chroot or jail
# Or from another login/uid,
#	including syntax from eg
#		http://www.berklix.com/~jhs/bin/.sh/xauth.sh
#		http://www.berklix.com/~jhs/bin/.sh/syntax
#	then I might even install flash

# JJLATER write something similar for chrome, as per mail to friends 2019-03-10
#	{
#	cc d GJ & NP.
#	LK. pointed me at a security vulnerability in chrome browser:
#	http://www.theregister.co.uk/2019/03/07/google_chrome_zero_day/
#
#		"The vulnerability affects Windows, Linux, Android, ChromeOS,
#		and macOS builds of Chrome:	if you are running version
#		72.0.3626.121 or higher (or 72.0.3626.122 or higher on
#		ChromeOS) then you are all good."
#
#		"According to Googler Abdul Syed, the ads giant is "aware
#		of reports that an exploit for CVE-2019-5786 exists in the
#		wild," meaning criminals and other miscreants are leveraging
#		the bug to infect victim s computers."
#
#	I discovered below, Chrome s been leaking data 2.5 months !
#	However, Non Tech s can glaze out here & skip rest of mail,
#	Just do an upgrade.
#	----------------------
#
#	FREEBSD Current:
#	 -----------
#	 Binary packages:
#		pkg info -a | grep chrom
#		chromium-72.0.3626.119	 Google web browser based on WebKit
#		# vulnerable
#		pkg update	# did not work, but a delete & reinstall did
#			# upgrade, (don not now why, maybe repository upgraded)
#	 Self built source is OK:
#		cd /usr/ports/www/chromium
#		cat distinfo
#			chromium-72.0.3626.121.tar.xz
#		make deinstall
#		make install
#		pkg info -a | grep chrom
#		chromium-72.0.3626.121_1 Google web browser based on WebKit
#	 -----------
#	ANDROID:
#	http://play.google.com/store/apps/details?id=com.android.chrome
#		Finaly found my release number: 72.0.3626.121
#			run chrome
#			3 vertical dots icon top right
#			Settings
#			About chrome
#			App. version
#		google play index page for chrome says app last updated 1 Mar
#	http://chromereleases.googleblog.com/2019/03/stable-channel-update-for-desktop.html
#		Bug also listed:	Friday, March 1, 2019
#
#	PS:	http://fossbytes.com/difference-google-chrome-vs-chromium-browser/
#		Google Chrome is a web browser developed and maintained by
#		tech giant Google. Chrome uses the open source web browser
#		Chromium s source code and adds a bunch of features developed
#		by Google and some nonfree components.
#
#	http://play.google.com/store/search?q=chrom&c=apps&authuser
#		I dont see any chromium just chrome
#
#	http://www.f-droid.org has
#		an app store for free binary apps based on public sources
#		has an app called getchromium, works:
#		http://search.f-droid.org/?q=chrom&lang=en
#			App version:	75.0.3731.0
#		That is a different number sequence
#	http://www.chromium.org/Home
#		Searching for CVE-2019-5786
#	http://bugs.chromium.org/p/chromium/issues/list?can=2&q=CVE-2019-5786&sort=&groupby=&colspec=&x=&y=&mode=&cells=&num=
#	http://bugs.chromium.org/p/chromium/issues/detail?id=917897&q=CVE-2019-5786
#		"All tested on Windows 10 + Google Chrome 71.0.3578.98,
#		full updated as of December 26, 2018."
#
#		"Feb 13" "Hi Google, We plan to publish this finding. "
#
#		"Feb 14 Are you able to make the release within next 2
#		weeks? We definitely can not wait till late April... because
#		(1) the exploit samples are already in the wild. (2) we have
#		waited for ~1.5 months since late December."
#
#		"Mar 1 by palmer@chromium.org This bug is now public, and
#		our policy is to open access to such bugs even if they are
#		not fixed. Also, making this bug public will clarify the
#		confused situation."
#
#	PS 1:	CVE:	An index run by USA govt:
#		http://en.wikipedia.org/wiki/Common_Vulnerabilities_and_Exposures
#
#	PS 2:	Reminds me I should write a sand box for chrome, like I did for firefox
#			http://www.berklix.com/~jhs/bin/.sh/firefox-clean
#		Because I have started using chrome a lot more in last month or so,
#		as firefox keeps crashing one me.
#	}

# -----------------------------------------------------------------------------

name=`basename $0`
PREAMBLE="$name: "
PREAMBLE=

mkdir -p ~/tmp

orbit=~/tmp/orbit-`whoami`
# I have also seen ~/tmp/orbit-`whoami`-a8e84818

if [ \! -d $orbit ]; then #{
	# echo "${PREAMBLE}	Firefox seems to not already be running, Good."
else	#}{
	echo "$name Error:	Directory exists:	$orbit"
	# If a firefox is runnning $orbit will contain a named pipe such as
	#	linc-61ae-0-3c8e64cba1214
	echo "${PREAMBLE}	So either Firefox is already running, or it crashed earlier."
	echo "${PREAMBLE}Suggestion:	rm -rf $orbit; `basename $name`"
	# ----------
	# I have seen an empty $orbit directory cause above message,
	# I assume thats from when firefox av been previously killed, &
	# control has not returned to a previous iteration of this script to
	#	So that if this script is called again,
	#	it wont fail twice but succeed second time.
	rm -rf $orbit
	# so it wont fail twice, but succeed second time.
	exit 1
fi	#}

uname=`uname -r`
case $uname in		#{
	#( for brackets.c
	9.2-RELEASE)	#{
		# ~/.mozilla/firefox/bqxvl6xt.default/prefs.js
		# ~/.mozilla/firefox/9rkadp9u.default/prefs.js
				 default=default
		;;	#}
	#( for brackets.c
	12.1-STABLE)	#{
		# ~/.mozilla/firefox/9mzqwp30.default-release/prefs.js
				 default=default-release
		;;	#}
	#( for brackets.c
	12.2-RELEASE)	#{
				 default=default-release
		;;	#}
	#( for brackets.c
	12.2-STABLE)	#{
		# ~/.mozilla/firefox/9j7uy4ms.default-esr/prefs.js
				 # default=default-esr
		# Not =default cos about 2020-12-15, pkg install firefox
		# started faliing, but pkg install firefoxesr was ok.
				 default=default-release
		;;	#}
	#( for brackets.c
	12.3-RELEASE)	#{
				 default=default-release
		;;	#}
	#( for brackets.c
	12.3-STABLE)	#{
				 default=default-release
		;;	#}
	#( for brackets.c
	12.4-RELEASE)	#{
				 default=default-release
		;;	#}
	#( for brackets.c
	12.4-STABLE)	#{
				 default=default-release
		;;	#}
	#( for brackets.c
	13.0-CURRENT)	#{
				 default=default-release
		;;	#}
	#( for brackets.c
	*)	#{
				 default=default
		echo "${PREAMBLE}Edit uname case list 0, add $uname"
		;;	#}
esac			#}

createit=no
HOME=~
# if [ \! -d ~/.mozilla_empty ]; then #{
#	echo "${PREAMBLE}mkdir ~/.mozilla_empty"
#	createit=yes
# fi	#}
if [ \! -d ~/.mozilla_empty/firefox ]; then #{
	echo "${PREAMBLE}mkdir -p ~/.mozilla_empty/firefox"
	createit=yes
fi	#}
# Next true is to satisfy brackets.c
if [ \! -d ~/.mozilla_empty/firefox/`true`*.$default ]; then #{
	# Next `true` is to seperate slash star C delimiter
	# to satisfy brackets.c
	echo -n "${PREAMBLE}Create "
	echo "~/.mozilla_empty/firefox/`true`*.$default/"
	createit=yes
fi	#}
oldprefs=~/.mozilla_empty/firefox/`true`*.$default/prefs.js
## if [ \! -f ~/.mozilla_empty/firefox/`true`*.$default/prefs.js ]; then
if [ \! -f ${oldprefs} ]; then
	#{
	echo "${PREAMBLE}Create ${oldprefs}"
	createit=yes
fi	#}

if [ "X${createit}" = "Xyes" ]; then #{
	echo "${PREAMBLE}Build ~/.mozilla_empty"
	echo "${PREAMBLE}Read `which $name`"
	echo "${PREAMBLE}Or Do this:"
	echo "${PREAMBLE}	rm -rf ~/.mozilla ~/.cache/.mozilla ~/.mozilla_empty"
	echo "${PREAMBLE}	firefox"
	echo "${PREAMBLE}	Edit preferences, till xterm shows it has created:"
	echo "${PREAMBLE}	ls -l ~/.mozilla/firefox/`true`*.default*`true`/prefs.js"
	# Usage of `true`:
	#	a subterfuge to seperate chars of / * and * /
	#	being C escape sequence for start and end of comment,
	#	to avoid brackets.c complaining of syntax error, umatched.
	# ~/.mozilla_empty/firefox:
	#	h8lz4rwy.default/ p4aj5oja.default-release/
	echo "${PREAMBLE}	Exit firefox"
	echo "${PREAMBLE}	mv ~/.mozilla ~/.mozilla_empty"
	#	2019-06-05 on current I notice no prefs.js just times.json
	#	 4310 v3sum8wn.default-release/prefs.js
	#	 50 v3sum8wn.default-release/times.json
	#	 47 vfug1k26.default/times.json*
	case $uname in		#{
		#( for brackets.c
		9.2-RELEASE)	#{
			# echo "${PREAMBLE}cp prefs.js ../`true`*.default/prefs.js"
			# identical in 9.2-RELEASE
			;;	#}
		#( for brackets.c
		12.1-STABLE)	#{
			echo "${PREAMBLE}	(cd ~/.mozilla_empty/firefox/`true`*.$default ; \\"
			echo "${PREAMBLE}	cp prefs.js ../`true`*.default/ )"
			# identical in 9.2-RELEASE
			;;	#}
		#( for brackets.c
		12.2-RELEASE)	#{
			echo "${PREAMBLE}	(cd ~/.mozilla_empty/firefox/`true`*.$default ; \\"
			echo "${PREAMBLE}	cp prefs.js ../`true`*.default/ )"
			;;	#}
		#( for brackets.c
		12.2-STABLE)	#{
			echo "${PREAMBLE}	(cd ~/.mozilla_empty/firefox/`true`*.$default ; \\"
			echo "${PREAMBLE}	cp prefs.js ../`true`*.default/ )"
			;;	#}
		#( for brackets.c
		12.3-RELEASE)	#{
			echo "${PREAMBLE}	(cd ~/.mozilla_empty/firefox/`true`*.$default ; \\"
			echo "${PREAMBLE}	cp prefs.js ../`true`*.default/ )"
			;;	#}
		#( for brackets.c
		12.4-RELEASE)	#{
			echo "${PREAMBLE}	(cd ~/.mozilla_empty/firefox/`true`*.$default ; \\"
			echo "${PREAMBLE}	cp prefs.js ../`true`*.default/ )"
			;;	#}
		#( for brackets.c
		12.3-STABLE)	#{
			echo "${PREAMBLE}	(cd ~/.mozilla_empty/firefox/`true`*.$default ; \\"
			echo "${PREAMBLE}	cp prefs.js ../`true`*.default/ )"
			;;	#}
		#( for brackets.c
		12.4-STABLE)	#{
			echo "${PREAMBLE}	(cd ~/.mozilla_empty/firefox/`true`*.$default ; \\"
			echo "${PREAMBLE}	cp prefs.js ../`true`*.default/ )"
			;;	#}
		#( for brackets.c
		13.0-CURRENT)	#{
			echo "${PREAMBLE}	(cd ~/.mozilla_empty/firefox/`true`*.$default ; \\"
			echo "${PREAMBLE}	cp prefs.js ../`true`*.default/ )"
			;;	#}
		#( for brackets.c
		*)	#		{
			echo "${PREAMBLE}	Edit uname case list 1, add $uname"
			;;	#}
	esac			#}
	#	2020-07-12 I see ~/.mozilla/firefox/g3szlq94.default/
	#		mimeTypes.rdf
	# echo "${PREAMBLE}	find ~/.mozilla* -name mimeTypes.rdf | xargs ls -l"
	#	There is no mimeTypes.rdf yet.
	echo "${PREAMBLE}Maybe: rm -rf tmp/orbit-`whoami`"
	# echo "${PREAMBLE}$name"
	exit 1
fi	#}

olddir=`cd ~/.mozilla_empty/firefox/*.$default;/bin/pwd`

case $uname in		#{
	#( for brackets.c
	9.2-RELEASE)	#{
		oldmimeTypes=`echo $olddir/mimeTypes.rdf`

		if [ \! -f ${oldmimeTypes} ]; then #{
			echo "${PREAMBLE}Caution: File does not exist:"
			echo "${PREAMBLE}Caution: ${oldmimeTypes}"
			echo "${PREAMBLE}Caution: It is not created at least initially on 12.1-STABLE but is on 9.2-RELEASE"
			echo "${PREAMBLE}Caution: If you want it on 9.2-RELEASE you can rebuild ~/.mozilla_empty :"
			echo "${PREAMBLE}Caution: Read `which $name`, or Do this:"
			echo "${PREAMBLE}Caution: cd ; rm -rf ~/.mozilla ~/.cache/.mozilla ~/.mozilla_empty"
			echo "${PREAMBLE}Caution: Immediately exit next firefox,"
			echo "${PREAMBLE}Caution: firefox ; mv ~/.mozilla ~/.mozilla_empty; $name"
		else	#}{
			# echo "${PREAMBLE}	OK, existant ${oldmimeTypes}"
		fi	#}
		;;	#}
	#( for brackets.c
	12.1-STABLE)	#{
		# creates no mimeTypes.rdf Nothing to do
		;;	#}
	#( for brackets.c
	12.2-RELEASE)	#{
		# creates no mimeTypes.rdf Nothing to do
		;;	#}
	#( for brackets.c
	12.2-STABLE)	#{
		# creates no mimeTypes.rdf Nothing to do
		;;	#}
	12.3-RELEASE)	#{
		# creates no mimeTypes.rdf Nothing to do
		;;	#}
	12.4-RELEASE)	#{
		# creates no mimeTypes.rdf Nothing to do
		;;	#}
	12.3-STABLE)	#{
		# creates no mimeTypes.rdf Nothing to do
		;;	#}
	#( for brackets.c
	13.0-CURRENT)	#{
		# creates no mimeTypes.rdf Nothing to do
		;;	#}
	#( for brackets.c
	*)		#{
		echo "${PREAMBLE}Edit uname case list 2, add $uname"
		;;	#}
esac			#}

rm -rf ~/.mozilla # Purge all hidden privacy encroachment, wherever.
rm -rf ~/.cache/mozilla

cp -R ~/.mozilla_empty ~/.mozilla
newdir=`cd ~/.mozilla/firefox/*$default;/bin/pwd`
newprefs=`echo $newdir/prefs.js`

case $uname in		#{
	#( for brackets.c
	9.2-RELEASE)	#{
		# newmimeTypes=`echo ~/.mozilla/firefox/*default/mimeTypes.rdf`
		newmimeTypes=`echo $newdir/mimeTypes.rdf`
		;;	#}
	#( for brackets.c
	12.1-STABLE)	#{
		;;	#}
	#( for brackets.c
	12.2-RELEASE)	#{
		;;	#}
	#( for brackets.c
	12.2-STABLE)	#{
		;;	#}
	#( for brackets.c
	12.3-RELEASE)	#{
		;;	#}
	#( for brackets.c
	12.4-RELEASE)	#{
		;;	#}
	#( for brackets.c
	12.3-STABLE)	#{
		;;	#}
	#( for brackets.c
	13.0-CURRENT)	#{
		;;	#}
	#( for brackets.c
	*)		#{
		echo "${PREAMBLE}Edit uname case list 3, add $uname"
		;;	#}
esac			#}

cp $newprefs ~/tmp/.$name.$$

# Strip suspicious obfuscated things.
cat ~/tmp/.$name.$$ \
 | grep -v app.update \
 | grep -v browser.newtabpage.blocked \
 | grep -v datareporting.sessions \
 | grep -v extensions.enabledAddons \
 | grep -v extensions.installCache \
 | grep -v intl.charsetmenu.browser.cache \
 | grep -v pdfjs.database \
								> $newprefs
# intl.charsetmenu.browser.cache is purged cos I hate UTF-8 that it asserts
rm ~/tmp/.$name.$$

# Below, I could read in $FTPSERVER, to make it more generic for other sites
# & users, but that would need work to get the quotes & delimeters right,
# & hardly seems worth it, as:
#	- "gate" is a pretty generic name people could easily put in their
#	 DNS or /etc/hosts.
#	- It might more likely break as other people may not have FTPSERVER set.

# Prefs below I may later move out to be user, host or site dependent.
# When eg remote browsing using a laptop on WLAN with NAT & no proxy.

# echo 'user_pref("browser.cache.disk.capacity", 51200);'	>> $newprefs

echo 'user_pref("browser.cache.disk.capacity", 0);'		>> $newprefs
# To disable cache for when I am editing local files with vi & want to review.

echo 'user_pref("browser.cache.disk.smart_size.enabled", false);'	\
								>> $newprefs
echo 'user_pref("browser.download.useDownloadDir", false);'	>> $newprefs
echo 'user_pref("browser.search.update", false);'		>> $newprefs
echo 'user_pref("browser.shell.checkDefaultBrowser", false);'	>> $newprefs
echo 'user_pref("browser.startup.homepage", "http://www.berklix.net/search/");' \
								>> $newprefs
echo 'user_pref("datareporting.healthreport.uploadEnabled", false);'	\
								>> $newprefs
echo 'user_pref("general.smoothScroll", false);'		>> $newprefs

echo 'user_pref("intl.accept_languages", "en,fr,de,it,nl,sp");' >> $newprefs
#	Observe with http://www.berklix.net/cgi-bin/printenv/
#	HTTP_ACCEPT_LANGUAGE="en,fr;q=0.8,de;q=0.7,it;q=0.5,nl;q=0.3,sp;q=0.2"

echo 'user_pref("layout.spellcheckDefault", 0);'		>> $newprefs

echo 'user_pref("widget.gtk.overlay-scrollbars.enabled", false);' \
								>> $newprefs

xx=`hostname -s` ; domain=`hostname|sed -e "s/$xx.//"` ; unset xx

case $domain in #{
	#( for brackets.c
	"js.berklix.net") #{
		echo 'user_pref("network.proxy.backup.ftp", "");'	\
								>> $newprefs
		echo 'user_pref("network.proxy.backup.ftp_port", 0);'	\
								>> $newprefs
		echo 'user_pref("network.proxy.backup.socks", "");'	\
								>> $newprefs
		echo 'user_pref("network.proxy.backup.socks_port", 0);' \
								>> $newprefs
		echo 'user_pref("network.proxy.backup.ssl", "");'	\
								>> $newprefs
		echo 'user_pref("network.proxy.backup.ssl_port", 0);'	\
								>> $newprefs
		echo 'user_pref("network.proxy.ftp", "gate");'	>> $newprefs
		echo 'user_pref("network.proxy.ftp_port", 80);' >> $newprefs
		echo 'user_pref("network.proxy.http", "gate");' >> $newprefs
		echo 'user_pref("network.proxy.http_port", 80);'	\
								>> $newprefs

		# JJLATER Remove internal host names
		# echo 'user_pref("network.proxy.no_proxies_on", "localhost, 127.0.0.1, blak,deli,dell,dual,erik,film,fire,gate,john,king,lapa,lapd,laph,lapl,lapn,lapo,lapr,laps,loft,mart,mini,park,rain,scan,slim,snow,sony,test,thin,wind");' \

		# JJLATER jhs-hv cant read as:
		#	cd ~jhs/private/bin Permission denied.

		hosts=`/site/usr/local/bin/hosts | sed -e 's/ /, /g'`
		echo 'user_pref("network.proxy.no_proxies_on", "localhost, 127.0.0.1, '"$hosts"'");' \
								>> $newprefs
		# js.berklix.net is temporarily removed (as it blocks proxy for
		# ap.w0.js.berklix.net), pending a named re-config
		# to move internal hosts to *.e0.js.berklix.net

		echo 'user_pref("network.proxy.share_proxy_settings", true);'	>> $newprefs
		echo 'user_pref("network.proxy.socks", "gate");'	\
								>> $newprefs
		echo 'user_pref("network.proxy.socks_port", 80);'	\
								>> $newprefs
		echo 'user_pref("network.proxy.ssl", "gate");'	>> $newprefs
		echo 'user_pref("network.proxy.ssl_port", 80);' >> $newprefs
		echo 'user_pref("network.proxy.type", 1);'	>> $newprefs
	;; #}
	#( for brackets.c
	"no.berklix.net") #{	ie wireless lan, let it run through natd
	;; #}
esac	# }

echo 'user_pref("pref.browser.language.disable_button.down", false);'	\
								>> $newprefs
echo 'user_pref("pref.browser.language.disable_button.remove", false);' \
								>> $newprefs
echo 'user_pref("pref.browser.language.disable_button.up", false);'	\
								>> $newprefs
echo 'user_pref("print_paper_height", "297.00");'		>> $newprefs
echo 'user_pref("print_paper_name", "iso_a4");'			>> $newprefs
echo 'user_pref("print_paper_width", "210.00");'		>> $newprefs
echo 'user_pref("print_to_filename", "$HOME/tmp/firefox.pdf");' >> $newprefs
echo 'user_pref("print_unwriteable_margin_bottom", 56);'	>> $newprefs
echo 'user_pref("print_unwriteable_margin_left", 25);'		>> $newprefs
echo 'user_pref("print_unwriteable_margin_right", 25);'		>> $newprefs
echo 'user_pref("print_unwriteable_margin_top", 25);'		>> $newprefs
echo 'user_pref("privacy.donottrackheader.enabled", true);'	>> $newprefs
echo 'user_pref("signon.rememberSignons", false);'		>> $newprefs

echo 'user_pref("widget.gtk.overlay-scrollbars.enabled", false);'>> $newprefs
#	Revert to old behaviour: Always show scroll bars.

# There are a whole load more settings shown by typing about:config into URL box,
# than appear in prefs.js, eg javascript.enabled
# One can find with /java then right click on java line then right
# click on Toggle.
# After setting them, on exiting firefox, they then get exported to prefs.js

# echo 'user_pref("javascript.enabled", false);'		>> $newprefs
# echo 'user_pref("javascript.enabled", true);'			>> $newprefs

# I have checked that if there is a double setting, the last one takes effect,
# & only the last one is saved back to prefs.js.

# Add handlers to mimeTypes.rdf for .pdf & .ps & .c & .diff etc

# This section below { was to
#	Add .pdf & .ps handlers to mimeTypes.rdf
# However I dont need it as PDF gets displayed internaly,
# & postscript auto invokes ghostview if found.
# Only problem is although FreeBSD-9.2-RELEASE has both
#	-rwxr-xr-x 1 root wheel 126128 Jan 24 2014 /usr/local/bin/ghostview*
#	-rwxr-xr-x 1 root wheel 1356308 Jan 24 2014 /usr/local/bin/gv*
# FreeBSD 12.0-CURRENT has no /ur/ports/print/ghostview, only gv,
# so manually do:	 ln -s gv /usr/local/bin/ghostview

# Retain header block:
#	<?xml version="1.0"?>
#	<RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"
#		 xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
#	 <RDF:Seq RDF:about="urn:schemes:root">
#	 <RDF:li RDF:resource="urn:scheme:webcal"/>
#	 <RDF:li RDF:resource="urn:scheme:ircs"/>
#	 <RDF:li RDF:resource="urn:scheme:mailto"/>
#	 <RDF:li RDF:resource="urn:scheme:irc"/>
#	 </RDF:Seq>
# Put new stuff before footer (easier than stripping & rebuilding multi line header).
# Strip footer line.
case $uname in		#{
	#( for brackets.c
	9.2-RELEASE)	#{
		grep -v '</RDF:RDF>' $newmimeTypes	> ~/tmp/.$name.$$
		;;	#}
	#( for brackets.c
	12.1-STABLE)	#{
		cp /dev/null				 ~/tmp/.$name.$$
		;;	#}
	#( for brackets.c
	12.2-RELEASE)	#{
		cp /dev/null				 ~/tmp/.$name.$$
		;;	#}
	#( for brackets.c
	12.2-STABLE)	#{
		cp /dev/null				 ~/tmp/.$name.$$
		;;	#}
	12.3-RELEASE)	#{
		cp /dev/null				 ~/tmp/.$name.$$
		;;	#}
	12.4-RELEASE)	#{
		cp /dev/null				 ~/tmp/.$name.$$
		;;	#}
	12.3-STABLE)	#{
		cp /dev/null				 ~/tmp/.$name.$$
		;;	#}
	#( for brackets.c
	13.0-CURRENT)	#{
		cp /dev/null				 ~/tmp/.$name.$$
		;;	#}
	#( for brackets.c
	*)		#{
		echo "${PREAMBLE}Edit uname case list 4, add $uname"
		;;	#}
esac			#}
	# Append handlers

	# I dont need to handle PDF as it gets displayed internaly,
	# echo ' <RDF:Description RDF:about="urn:mimetype:externalApplication:application/pdf"'\
	#						>> ~/tmp/.$name.$$
	# echo ' NC:path="/usr/local/bin/xpdf" NC:prettyName="xpdf" />'\
	#						>> ~/tmp/.$name.$$

	# I dont need to handle postscript as it auto invokes ghostview if found.
	# Only problem is although FreeBSD-9.2-RELEASE has both
	#	-rwxr-xr-x 1 root wheel 126128 Jan 24 2014 /usr/local/bin/ghostview*
	#	-rwxr-xr-x 1 root wheel 1356308 Jan 24 2014 /usr/local/bin/gv*
	# FreeBSD 12.0-CURRENT has no /ur/ports/print/ghostview, only gv,
	# so manually do:	 ln -s gv /usr/local/bin/ghostview
	# I think OK for FreeBSD 9.2-RELEASE, but did not work for host=lapr 12.0-CURRENT
	# echo ' <RDF:Description RDF:about="urn:mimetype:externalApplication:application/postscript"'\
	#						>> ~/tmp/.$name.$$
	# echo ' NC:path="/usr/local/bin/gv" NC:prettyName="gv" />'\
	#						>> ~/tmp/.$name.$$

# Add handler for a diff of a .c file :
echo ' <RDF:Description RDF:about="urn:mimetype:externalApplication:text/x-c"'\
							>> ~/tmp/.$name.$$
echo ' NC:path="/usr/local/bin/xvile" NC:prettyName="xvile" />'\
	>> ~/tmp/.$name.$$

# Append new footer.
echo '</RDF:RDF>'					>> ~/tmp/.$name.$$
case $uname in		#{
	#( for brackets.c
	9.2-RELEASE)	#{
		cat ~/tmp/.$name.$$			> $newmimeTypes
		;;	#}
	#( for brackets.c
	12.1-STABLE)	#{
		;;	#}
	#( for brackets.c
	12.2-RELEASE)	#{
		;;	#}
	#( for brackets.c
	12.2-STABLE)	#{
		;;	#}
	#( for brackets.c
	12.3-RELEASE)	#{
		;;	#}
	#( for brackets.c
	12.4-RELEASE)	#{
		;;	#}
	#( for brackets.c
	12.3-STABLE)	#{
		;;	#}
	#( for brackets.c
	13.0-CURRENT)	#{
		;;	#}
	#( for brackets.c
	*)	#		{
		echo "${PREAMBLE}Edit uname case list 5, add $uname"
		;;	#}
esac			#}
rm ~/tmp/.$name.$$
# }

# Temporary hack to observe startup speed
echo "firefox-clean about to call firefox `date`" > ~/tmp/firefox-clean.date
cat ~/tmp/firefox-clean.date
## cat ~/tmp/firefox-clean.date >> ~/tmp/firefox-clean.log
rm ~/tmp/firefox-clean.date

# JJLATER I could make it harder for trackers by
#	pppctl down # See ~/private/html/bin/.csh/dsl
#	sleep 5 # Let someone else acqure last D-DNS IP.
#	however, bad idea as other processes host & wlan may be using net,
#	maybe depend on domain eg
#		js.berklix.com: no down
#		no.berklix.net:	yes down

if [ "x$#" == "x0" ] ; then	#{{
	# firefox	# pre 2021-01-20
	firefox http://localhost/~jhs/
else				#}{
	firefox $*		# I could reduce it to just $1
fi				#}}

# rmdir ~/tmp/orbit-`whoami`	# complains Directory not empty
rm -rf ~/tmp/orbit-`whoami`

echo "${PREAMBLE}	Later consider using /usr/local/bin/ Xnest Xephyr"
