Last active
August 21, 2017 01:39
-
-
Save maxwelleite/4ac78d2f3f89a5974b53 to your computer and use it in GitHub Desktop.
Script to automatic download, install and configure the language pack on Firefox [Ubuntu/Debian distros]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: Maxwel Leite | |
# file-name: firefox-language-installer.sh | |
# Website: http://needforbits.wordpress.com/ | |
# Description: Script to automatic download, install and configure the language pack on Firefox [Ubuntu/Debian distros] | |
# Dependencies: firefox-mozilla-build (Ubuntuzilla Repository) or firefox (obvious!) and wget | |
# Tested: Ubuntu 14.04 (Trusty), 13,10 (Saucy) | |
# License: GPLv3 | |
# Note: Also works with Firefox installed from compressed tarball (ex: firefox-33.1.1.tar.bz2) | |
# TODO: Test in Debian | |
if [[ $EUID -eq 0 ]]; then | |
echo -e "\nError!\n\nPlease, don't try to install as root user!\n\nUse only as normal user:\n\n./${0##*/}\n\nOr simply:\n\nbash ${0##*/}\n" | |
exit | |
fi | |
if ! which wget >/dev/null; then | |
echo "Error: **wget** is required to download the file" | |
echo "Run the following command to install it:" | |
echo "sudo apt-get install wget" | |
exit | |
fi | |
if ! which firefox >/dev/null; then | |
echo "Error: firefox is very... very required ;-P" | |
echo "Run the following command to install it:" | |
echo "sudo apt-get install firefox" | |
exit | |
fi | |
# get the current Firefox version | |
ffver=`/usr/bin/firefox -v | awk '{ print $3 }'` | |
clear | |
echo '' | |
# get prefs.js location | |
prefsjs="$HOME/.mozilla/firefox/$(cat ~/.mozilla/firefox/profiles.ini|grep Path|sed s/Path=//)/prefs.js" | |
# get the system language code from environment | |
langid=$(echo $LANG | cut -d. -f1 | sed 's/\_/\-/g') | |
# get architecture of OS | |
case `uname -i` in | |
i386|i486|i586|i686) arch='linux-i686';; | |
x86_64) arch='linux-x86_64';; | |
esac | |
# building the url for download the XPI package | |
urlxpi="http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/$ffver/$arch/xpi/$langid.xpi" | |
echo 'Firefox Language Installer' | |
echo '' | |
echo 'Detected info:' | |
echo '' | |
echo "Firefox version: $ffver" | |
echo "OS Architecture: `uname -i`" | |
echo "OS Language ID: $langid" | |
echo '' | |
if [ -n "$1" ]; then | |
langid=$1 | |
echo -e "Forced Language ID: $langid\n" | |
fi | |
# Check if Firefox is running | |
printf ":: Checking if Firefox is running... " | |
if `pidof firefox >/dev/null`; then | |
printf 'Error!\n\n' | |
echo "Please close the Firefox before do this." | |
echo 'Try again after close it.' | |
echo '' | |
exit | |
else | |
printf "Done!\n" | |
fi | |
printf ":: Checking available for '$langid' language pack... " | |
httpstatus=`wget --spider -S "$urlxpi" 2>&1 | grep "HTTP/" | awk '{print $2}'` | |
case $httpstatus in | |
404) | |
printf "Error!\n\n" | |
echo "Looks like that's not yet any language pack for ''$langid''!" | |
echo '' | |
echo "Try install manually, example:" | |
echo "./${0##*/} pt-BR" | |
echo '' | |
echo "Note: ''pt-BR'' is the language id for Portuguese (Brazilian)" | |
echo '' | |
echo "See the list of available language packs codes from here:" | |
echo '' | |
echo "http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/$ffver/$arch/xpi/" | |
echo '' | |
exit | |
;; | |
200) | |
printf "Done!\n" | |
;; | |
*) | |
printf "Error!\n\n" | |
echo "Download Error!? Please try again!" | |
exit | |
;; | |
esac | |
printf ":: Downloading the language pack add-on file... " | |
if wget -q -O /tmp/firefox-lang.xpi -q "$urlxpi" > /dev/null; then | |
printf "Done!\n" | |
else | |
printf "Error!\n\n" | |
echo "Download Error! Please try again!" | |
fi | |
# Checking again if Firefox is running - just in case ;-) | |
if `pidof firefox >/dev/null`; then | |
echo -e "\nError!\n" | |
echo "Please close the Firefox before do this." | |
echo 'Try again after close it.' | |
echo '' | |
exit | |
fi | |
printf ":: Setting default Locale in Firefox... " | |
if ! grep general.useragent.locale $prefsjs > /dev/null; then | |
printf "Done!\n" | |
echo 'user_pref("general.useragent.locale", "'$langid'");' | tee -a $prefsjs > /dev/null | |
else | |
printf "Done!\n" | |
sed -i 's|\("general.useragent.locale",\) "\(.*\)"|\1 "'$langid'"|' $prefsjs | |
fi | |
echo ":: Installing language pack in Firefox... " | |
echo -e "\n\nNow will be open Firefox and is needed to confirm the install of the language pack.\n\n**You must need press \"Install Now\" when asked and then close the Firefox**.\n" | |
read -p "Press [Enter] key to continue..." | |
/usr/bin/firefox /tmp/firefox-lang.xpi & | |
## Wait to finish the firefox instance. | |
while `pidof firefox >/dev/null`; | |
do | |
sleep 1 | |
done | |
#cleanup | |
clear | |
echo '' | |
printf ":: Cleanup... " | |
rm -rf /tmp/firefox-lang.xpi | |
sleep 1 | |
printf "Done!\n\n" | |
printf "That's it!\nNow just reopen the Firefox and enjoy!\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment