37

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)

wget https://addons.mozilla.org/firefox/downloads/latest/1865/addon-1865-latest.xpi
firefox -silent -install-global-extension addon-1865-latest.xpi -setDefaultBrowser www.google.es

Thanks in advance.

2
  • Added instructions to automate the installation of an addon, if you need a script let me know, its possible. Oct 29, 2011 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, 2012 at 11:01

9 Answers 9

30

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 though!

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
wget https://addons.mozilla.org/firefox/downloads/latest/1865/addon-1865-latest.xpi

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", "http://uptechtalk.com");

or using this command

echo "user_pref("browser.startup.homepage", "http://uptechtalk.com");" >> ~/.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", "http://uptechtalk.com");" >> /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

8
  • 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, 2012 at 6:45
  • install-global-extension is deprecated.
    – learner
    Jun 6, 2013 at 11:18
  • 1
    I've often wondered about the inner workings of the extensions system, a lot of good info here, thanks!
    – Madd0g
    Jan 23, 2014 at 1:54
  • 1
    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, 2014 at 15:57
  • 2
    I think the install.rdf or at least the id inside of it is not necessarily present in WebExtensions. Note, by the end of 2017 Firefox will drop support for extensions other than WebExtensions.
    – Forivin
    Feb 14, 2017 at 14:04
5

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_SYSTEM='/usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/'
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 () {
    xpi="${PWD}/${1}"
    extensions_path=$2
    new_filename=`get_addon_id_from_xpi $xpi`.xpi
    new_filepath="${extensions_path}${new_filename}"
    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."
    else
        cp "$xpi" "$new_filepath"
    fi
}

Let's install Adblock..

wget https://addons.mozilla.org/firefox/downloads/latest/1865/addon-1865-latest.xpi
install_addon addon-1865-latest.xpi "$EXTENSIONS_USER"
1
  • Thanks, this is now the correct path to use for a silent install
    – myol
    May 1, 2016 at 7:14
3

For latest versions of Firefox, the procedure has been simplified a lot!

  1. Unzip extension.xpi
  2. Read applications.gecko.id from manifest.json
  3. Rename extension.xpi to <ID>.xpi
  4. Copy to one of the standard installation folders listed here
2

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.

`

----------------------------------------------------------------------
#!/bin/bash

pjsbase="/data/M_drive/Temp/prefsjs"

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
  grep extensions.enabledItems ${pjsbase}/${userf} | 
  /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
  /bin/sed 's/0\.3\.8\.[0-9]*/0\.3\.8\.4/g' ${pjsbase}/tmp1 > ${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\"\,\ \"2.12.21.1\"\)\; >> \
     ${pjsbase}/${userf}.new2
  echo user_pref\(\"extensions.update.notifyUser\"\,\ false\)\; >> \
     ${pjsbase}/${userf}.new2
  # if they have a preference list then migrate it
  if [ ! `grep user_pref\(\"ietab.filterlist\" ${pjsbase}/${userf} |
          wc -l` -eq 0 ]; then
    echo "user_pref(\"extensions.ietab2.filterlist"$(
       grep user_pref\(\"ietab.filterlist\" ${pjsbase}/${userf} | 
       sed 's/user\_pref(\"ietab\.filterlist//')"" >> ${pjsbase}/${userf}.new2
  fi
  # make sure prefs are alphabetised
  egrep -v ^u > ${pjsbase}/${userf}.new ${pjsbase}/${userf}.new2
  egrep ^u  ${pjsbase}/${userf}.new2 | sort >> ${pjsbase}/${userf}.new
done

`

2

PLEASE BE AWARE

From Firefox 74, it is now NO LONGER POSSIBLE to perform this task.

Don't pour hours into trying to make this work any more!

0
1

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

#!/bin/sh
var=`grep -m 1 -e em:id install.rdf`   
var=${var#*\>}
var=${var%<*}

...giving you the id (including the {}).

1

Firefox add-ons one liner. Adblock Plus, FlashBlock, and Download Helper downloaded in that order, then in firefox opening all found .xpi files, then removing those .xpi files:

wget \ 
 https://addons.mozilla.org/firefox/downloads/latest/1865/addon-1865-latest.xpi \ 
 https://addons.mozilla.org/firefox/downloads/latest/433/addon-433-latest.xpi \
 https://addons.mozilla.org/firefox/downloads/latest/3006/addon-3006-latest.xpi && 
firefox *.xpi && rm *.xpi
0

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 addons.mozilla.org. 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.

#!/bin/bash
extensionnumber=$1

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

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

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

upstream=""https://addons.mozilla.org/firefox/downloads/latest"

# get extension and unzip
wget -O extension.xpi \
  "${upstream}/${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`   
extensionid=${extensionid#*\>}
extensionid=${extensionid%<*}

# 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
2
0

For completeness, I found another very well-documented script on http://bernaerts.dyndns.org/linux/74-ubuntu/271-ubuntu-firefox-thunderbird-addon-commandline which is basically doing exactly what Bruno Pereira suggested in his answer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .