#!/bin/bash
#
# installnewfirefox.sh
# Script to automatically download and install the newest firefox version for linux, on an Ubuntu system.
# Requires an internet connection to work (obviously).
#
# Author: nanotube <nanotube@users.sf.net>.
#
# Version: installnewfirefox.sh 2.14 11-Nov-2006
nanotube@users.sf.net
#
#
#######
## Make sure that we exit if any commands do not complete successfully.
set -o errexit
trap 'echo "Previous command did not complete successfully. Exiting."' ERR
## Set version-specific variables
if grep -q "5.10" /etc/issue ; then
PLUGINPATH=/usr/lib/mozilla-firefox/plugins
elif grep -q "6.06" /etc/issue ; then
PLUGINPATH=/usr/lib/firefox/plugins
elif grep -q "6.10" /etc/issue ; then
PLUGINPATH=/usr/lib/firefox/plugins
else
echo "This script only works on Breezy, Dapper, or Edgy."
exit 1
fi
## Get the newest firefox release version from mozilla website
VERSION=`wget -q -O - http://www.mozilla.com |grep "product=" -m 1 |sed -e 's/.*<li>.*firefox-//' -e 's/&.*//'`
echo -e -n "The most recent release of firefox is detected to be $VERSION. Please make sure this is correct before proceeding. (You can confirm by going to http://www.mozilla.com/) Is it correct [y/n]? "
while true
do
read ans
case $ans in
Y|y|[Yy][Ee][Ss])
break ;;
N|n|[Nn][Oo])
echo "If this does not agree with the latest version as listed on mozilla.com, please contact
nanotube@users.sf.net and let me know.";
exit ;;
*)
echo -n "Invalid command. Please answer yes or no [y/n] " ;;
esac
done
echo -e "\nUpdating repositories list\n"
sudo aptitude update
echo -e "\nMaking sure libstdc++5 and the old Firefox are installed\n"
sudo aptitude install firefox libstdc++5
if [ -d ~/.mozilla ]; then
echo -e "\nBacking up old Firefox preferences\n"
cp -R ~/.mozilla ~/.mozilla_backup_`date -Iseconds`
else
echo -e "\nOld firefox preferences not found. Nothing to back up. Proceeding with installation.\n"
fi
echo -e "\nChanging to home directory\n"
cd
echo -e "\nDownloading Firefox archive from the Mozilla site\n"
wget -c http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/$VERSION/linux-i686/en-US/firefox-$VERSION.tar.gz
echo -e -n "The next step will verify the GPG signature for the firefox archive to assure its integrity. This step is important for your security. However, if you have problems getting this to work right, you may choose 'no' and proceed to installation without signature verification. Do you want to verify the signature [y/n]?"
while true
do
read ans
case $ans in
Y|y|[Yy][Ee][Ss])
echo -e "\nDownloading Firefox signature from the Mozilla site\n"
wget -c http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/$VERSION/linux-i686/en-US/firefox-$VERSION.tar.gz.asc
echo -e "\nImporting Mozilla Software Releases public key\n"
echo -e "Note that if you have never used gpg before on this system, and this is your first time running this script, there may be a delay of about a minute during the generation of a gpg keypair. This is normal and expected behavior.\n"
gpg --keyserver subkeys.pgp.net --recv 1AF32821
echo -e "\nVerifying signature...\nNote: do not worry about \"untrusted key\" warnings. That is normal behavior for newly imported keys.\n"
gpg --verify firefox-$VERSION.tar.gz.asc firefox-$VERSION.tar.gz
break ;;
N|n|[Nn][Oo])
echo "Proceeding without signature verification..."; break ;;
*)
echo -n "Invalid command. Please answer yes or no [y/n] " ;;
esac
done
echo -e "\nExtracting the downloaded Firefox archive\n"
sudo tar -C /opt -xzf firefox-$VERSION.tar.gz
echo -e "\nRemoving installation file(s) to free up disk space\n"
rm -f firefox-$VERSION.tar.gz firefox-$VERSION.tar.gz.asc
echo -e "\nLinking plugins\n"
sudo mv /opt/firefox/plugins /opt/firefox/plugins_`date -Iseconds`
sudo ln -s -f $PLUGINPATH /opt/firefox/plugins
echo -e "\nLinking launcher to new Firefox\n"
sudo dpkg-divert --divert /usr/bin/firefox.ubuntu --rename /usr/bin/firefox
sudo ln -s -f /opt/firefox/firefox /usr/bin/firefox
sudo dpkg-divert --divert /usr/bin/mozilla-firefox.ubuntu --rename /usr/bin/mozilla-firefox
sudo ln -s -f /opt/firefox/firefox /usr/bin/mozilla-firefox
echo -e "\nThe new Firefox version $VERSION has been installed successfully."
exit