I was having troubles with updating firefox on linux. The update firefox window used to get stuck on
“connecting to server”. So I wrote this simple script to update firefox. Hope it helps.
#!/bin/bash url="http://ftp.jaist.ac.jp/pub/mozilla.org/firefox/releases" ver="10.0.2" arch="linux-i686" lang="en-US" tarname="" tar="tar.bz2" download=1 isroot(){ uid=`id -u`; if [ $uid -ne 0 ] then echo "the script must be used in elevated mode"; exit; fi } parseargs(){ while getopts "nv:a:l:" ARGS do case $ARGS in v) ver=$OPTARG ;; a) arch=$OPTARG ;; l) lang=$OPTARG ;; n) download=0 ;; ?) echo "invalid arguments" exit ;; esac done } create_url(){ tarname="firefox-$ver" url=$url/$ver/$arch/$lang/$tarname.$tar; } fetch_firefox(){ if [ $download -ne 0 ];then curl $url -o "$tarname.$tar" fi } update_firefox(){ tar -xf ./$tarname.$tar -C /tmp if [ -d /usr/lib/$tarname ];then #rm -rf /usr/lib/$tarname #to be safe echo "please remove /usr/lib/$tarname directory manually and re-run the script with -n as a parameter" exit fi cp -r /tmp/firefox /usr/lib/$tarname rm /usr/bin/firefox ln -s /usr/lib/$tarname/firefox /usr/bin/firefox } isroot; parseargs $@; create_url; fetch_firefox update_firefox
This script needs to be run in elevated mode with all the optional parameters:
1. -v version_number: e.g -v 10.0.2. At the time this code was written the version was 10.0.2, so I kept it the default version.
2. -a cpu arch type: one of the two: linux-i686 or linux-i86_64. Default type is linux-i686.
3. -l language: the language of firefox, default is en-US.
4. -n : this switch can be used if the tar is already downloaded and located in the current folder of the script.
I havent done any error checking, so if the script fails you wont get much info about the failure.
example usages:
1) ./updatefirefox.sh -v 10.0.2 -a linux-i86_64: To update to 10.0.2 on x86_64 arch.
2) ./updatefirefox.sh -v 10.0.2 -l en-GB: To update to 10.0.2 on en-GB locale.
3) ./updatefirefox.sh -v 10.0.2 -n : To update firefox with an already downloaded tar file located in the
current folder.
Feel free to modify the script to improve it. If there is some serious bug in the code, please let me know.
And although it is trivial for many of us but if its not then the challenge for you is to figure out how to
find out the language code? 🙂
If I get some time, I will improve the script and also give a detailed explanation of how it works. Till then Share the Firefox Love. 🙂