Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to improve my unattended script adding some Firefox addon, however I cant find the way,

Can someone help to find out how to?

Example: (Want to install adblockPlus plugin and set a new default webpage)

firefox -silent -install-global-extension addon-1865-latest.xpi -setDefaultBrowser

Thanks in advance.

share|improve this question
Added instructions to automate the installation of an addon, if you need a script let me know, its possible. – Bruno Pereira Oct 29 '11 at 14:30
This is a great question now since im now strugling to find way to CLI way install Adblock package as previously on 10.04 with just apt-get install adblock-plus witch doesnt exist in 11.10 :( AND YES- we need script :) – Kangarooo Mar 3 '12 at 11:01

Using your method

gksudo firefox -install-global-extension addon-1865-latest.xpi seems to do the trick for you. That will install the extension to all users on your system.

To install the extension only for your user use the extension path as an argument

firefox addon-1865-latest.xpi

You still need to click the Install button tough!

Automating the installation

Firefox does not need the addon file name but the identifier from the addon as a package name. That means that if you are planning on installing an addon without user intervention you need to extract it to a folder with the name of the addon identifier string, not the name of the addon.

The identifier string can be found on the first lines of the addon install manifest file install.rdf and it looks like this: <em:id>{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}</em:id>. Everything within the {} (including the curly braces) is the identifier.

To get an addon to work you need to extract the package, rename the folder that contains the files to the addon identifier string and place it either on the global addon folder or within the user addon folder.

Global addon install

If you want to install an extension automatically to all users in your system you need to extract it, rename the folder that contains the addon to the addon's id string and copy it to the firefox global extensions folder /usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/, anything that you use there will be called up automatic when a user opens firefox.

User specific install

If you want to install an extension automatically to just one user in your system you need to extract it, rename the folder that contains the addon to the addon's id string and copy it to the firefox user extensions folder /home/user_name/.mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/ (create it if it does not exist), anything that you use there will be called up automatic when a user opens firefox.

How-to prepare an addon for automatic install - Example

Make an extensions folder in your home and download the addon in to it

mkdir ~/extensions
cd ~/extensions

Extract it and delete the original

unzip ~/extensions/addon-1865-latest.xpi
rm ~/extensions/addon-1865-latest.xpi

Read the first line in the install.rdf file to get the addon's id (in this case it will be {d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}). and create a folder with that name

mkdir ~/extensions/{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}

Move all the files in your extensions folder into the newly created ~/extensions/{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d} and you are ready to install by moving the {d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d} folder, as described, for a local install or for a global install.

How-to set the default home page

To change your homepage without using the preferences inside firefox you have to edit ~/.mozilla/firefox/*.default/prefs.js (where *.default is a folder inside ~/.mozilla/firefox created for your user) and add this line to the end of it

user_pref("browser.startup.homepage", "");

or using this command

echo "user_pref("browser.startup.homepage", "");" >> ~/.mozilla/firefox/*.default/prefs.js

You need to do it after closing firefox or the program will overwrite the setting on exit.

If your user has not used firefox yet and you want to set the homepage for all new users (set homepage globally) use this command

echo "user_pref("browser.startup.homepage", "");" >> /etc/xul-ext/ubufox.js

Comments about your question

-silent does not exist, you will be prompted to install that xpi extension anyways and you have to click the button to install it;

-setDefaultBrowser will not set your homepage, it will make firefox your default browser

share|improve this answer
gksudo firefox -install-global-extension addon-1865-latest.xpi makes only for all new users EXEPT Guest yes? Couse i did it and guest has still no plugins. – Kangarooo May 18 '12 at 6:45
install-global-extension is deprecated. – learner Jun 6 '13 at 11:18
I've often wondered about the inner workings of the extensions system, a lot of good info here, thanks! – Madd0g Jan 23 '14 at 1:54
Cheers, hope its useful somehow! – Bruno Pereira Jan 23 '14 at 13:07
If you have bunch of addon, I suggest you to use FEBE addon, it will extract all your addons into one and simplify much of your code :D – Ooker Apr 1 '14 at 15:57

This is problematic since in different versions of Firefox, different things work and at some nothing work. For the newer versions you just have to rename the .xpi to <addon id>.xpi and place it in an extensions folder. When you start firefox afterwards, you will be asked to accept the installation of all addons you added there.

Here is some BASH functions that make your life easier..

EXTENSIONS_USER=`echo ~/.mozilla/firefox/*.default/extensions/`

# -------------------------- xpi tools ---------------------------------

get_addon_id_from_xpi () { #path to .xpi file
    addon_id_line=`unzip -p $1 install.rdf | egrep '<em:id>' -m 1`
    addon_id=`echo $addon_id_line | sed "s/.*>\(.*\)<.*/\1/"`
    echo "$addon_id"

get_addon_name_from_xpi () { #path to .xpi file
    addon_name_line=`unzip -p $1 install.rdf | egrep '<em:name>' -m 1`
    addon_name=`echo $addon_name_line | sed "s/.*>\(.*\)<.*/\1/"`
    echo "$addon_name"

# Installs .xpi given by relative path
# to the extensions path given
install_addon () {
    new_filename=`get_addon_id_from_xpi $xpi`.xpi
    addon_name=`get_addon_name_from_xpi $xpi`
    if [ -f "$new_filepath" ]; then
        echo "File already exists: $new_filepath"
        echo "Skipping installation for addon $addon_name."
        cp "$xpi" "$new_filepath"

Let's install Adblock..

install_addon addon-1865-latest.xpi "$EXTENSIONS_USER"
share|improve this answer
Thanks, this is now the correct path to use for a silent install – myol May 1 at 7:14

Firefox Addons one liner- Adblock Plus, FlashBlock, Download Helper Downloading in upper order && opened all found *.xpi in firefox && removing all *.xpi for feeling nothing different done

wget && wget && wget && firefox *.xpi && rm *.xpi
share|improve this answer

Global plugins are not enabled by default, and you need to add them to the list in the prefs.js file in their profile in order for them to be enabled. A major pain for mass deployments.

Here's a sample script for when we dumped a bunch of prefs.js files from client machines up to the network and changed from IETab to IETab2, migrated their preferences, etc.

Another way is to create a user profile you like on a box, upload it to the network, then clone it across machines in Firefox\defaults\profile and all new users will inherit that profile.




for userf in `find ${pjsbase} -maxdepth 1 -type f -name *.prefs.js -printf "%f\n"` ; do
  echo ${userf}
# add in IETab2 GUID and remove IETab GUID
  cat ${pjsbase}/${userf} | grep extensions.enabledItems | /bin/sed 's/\")/\,\{1BC9BA34-1EED-42ca-A505-6D2F1A935BBB\}\:2\.12\.21\.1\")/' | /bin/sed 's/{77b819fa-95ad-4f2c-ac7c-486b356188a9}:1.5.20090525,//' > ${pjsbase}/tmp1
  cat ${pjsbase}/tmp1 | /bin/sed 's/0\.3\.8\.[0-9]*/0\.3\.8\.4/g' > ${pjsbase}/tmp
  /bin/sed /extensions.enabledItems/d ${pjsbase}/${userf} > ${pjsbase}/tmp2
  cat ${pjsbase}/tmp2 > ${pjsbase}/${userf}.new2
  cat ${pjsbase}/tmp >> ${pjsbase}/${userf}.new2
# add in IETab2 preferences
  echo user_pref\(\"extensions.ietab2.hasRun\"\,\ true\)\; >> ${pjsbase}/${userf}.new2
  echo user_pref\(\"extensions.ietab2.ietab2PrefsMigrated\"\,\ true\)\; >> ${pjsbase}/${userf}.new2
  echo user_pref\(\"extensions.ietab2.prefsMigrated\"\,\ true\)\; >> ${pjsbase}/${userf}.new2
  echo user_pref\(\"extensions.ietab2.version\"\,\ \"\"\)\; >> ${pjsbase}/${userf}.new2
  echo user_pref\(\"extensions.update.notifyUser\"\,\ false\)\; >> ${pjsbase}/${userf}.new2
# if they have a preference list then migrate it
  if [ ! `cat ${pjsbase}/${userf} | grep user_pref\(\"ietab.filterlist\" | wc -l` -eq 0 ]; then
    echo "user_pref(\"extensions.ietab2.filterlist"`cat ${pjsbase}/${userf} | grep user_pref\(\"ietab.filterlist\" | sed 's/user\_pref(\"ietab\.filterlist//'`"" >> ${pjsbase}/${userf}.new2
# make sure prefs are alphabetised
  cat ${pjsbase}/${userf}.new2 | egrep -v ^u > ${pjsbase}/${userf}.new
  cat ${pjsbase}/${userf}.new2 | egrep ^u | sort >> ${pjsbase}/${userf}.new


share|improve this answer

For some of you this shell script might be helpfuel. It parses the first occurence of the em:id tag in the install.rdf (described by Bruno Pereira)

var=`grep -m 1 -e em:id install.rdf`   

giving you the id (including the {})


share|improve this answer

I created a simple script based on Bruno's answer.

It installs an extension for the current user without any interaction needed. You only need the number Mozilla uses in their URLs on Save the script as a .sh file and use the number as an argument when you call it.

Tested and working on Linux Mint 17 with Firefox 40, be sure to check if your version of Firefox uses the same directory structure since they changed it around a few times.


# find profile dir (first profile in the ini file)
profiledir=`cat ${HOME}/.mozilla/firefox/profiles.ini | sed -n -e 's/^.*Path=//p' | head -n 1`

if [ -z "$profiledir" ]; then
    printf "Can't find profile directory."
    exit 1

mkdir /tmp/extension
cd /tmp/extension || exit $?

# get extension and unzip
wget -O extension.xpi "${extensionnumber}/addon-${extensionnumber}-latest.xpi" || exit $?
unzip extension.xpi && rm extension.xpi

# get extension id from installation file
extensionid=`grep -m 1 -e em:id install.rdf`   

# move all files to the directory with the right id
mkdir $extensionid || exit $?
shopt -s extglob dotglob
mv !($extensionid) $extensionid/
shopt -u dotglob

# create new firefox extension dir (if it's a clean install) and move the extension
mkdir -p "${extensiondir}"
mv "${extensionid}" "${extensiondir}"

rmdir /tmp/extension
printf "Installed extension."
exit 0
share|improve this answer

protected by Community Oct 31 '15 at 20:32

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.