#!/bin/sh
#
# Install latest Firefox release in any Ubuntu using Ubuntuzilla repository.
#
# Stephen Thomas <flabdablet@gmail.com> 7-Feb-2010
#
# This is free software. Do whatever you like with it except
# hold me accountable for the grief it will surely cause you.

quit () {
	local status=$?
	test -n "$1" && echo "$@" >&2
	local line
	read -p 'Press Enter: ' line
	exit $status
}

tryserver () {
	local listfile=/etc/apt/sources.list.d/ubuntuzilla.list
	sudo tee <<-. "$listfile" >/dev/null || quit "Can't write $listfile"
		deb http://$1.sourceforge.net/project/ubuntuzilla/mozilla/apt all main
		.
	sudo apt-get update -qq 2>/dev/null || {
		local status=$?
		sudo rm "$listfile"
		return $status
	}
}

cat <<-.

	This script will install the latest release of Firefox
	and let your package manager keep it up to date. Please
	enter your password to authorize it to do that.

	.
sudo cat /dev/null
echo "Adding Ubuntuzilla package signing key..."
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com C1289A29 >/dev/null 2>&1 || quit "Can't add signing key."
echo "Updating package manager..."
sudo apt-get update -qq || quit "Can't update package manager."
echo "Adding Ubuntuzilla repository..."
tryserver downloads || tryserver switch.dl || quit "Can't add ubuntuzilla repository."
echo "Installing Firefox..."
sudo apt-get -qq install firefox-mozilla-build || quit "Can't install Firefox."
quit "Done."

