Skip to content

Instantly share code, notes, and snippets.

@pirpyn
Last active October 31, 2019 11:12
Show Gist options
  • Save pirpyn/9fc62b3a559d7b9d3c94e8f38f04e896 to your computer and use it in GitHub Desktop.
Save pirpyn/9fc62b3a559d7b9d3c94e8f38f04e896 to your computer and use it in GitHub Desktop.
Add an addons from its xpi url
#!/bin/bash -e
# https://askubuntu.com/questions/73474/how-to-install-firefox-addon-from-command-line-in-scripts
if [[ -f $0 ]]; then
scriptname=$(basename $(readlink -f $0))
else
scriptname="firefox_install_addons.sh"
fi
usage() { cat << EOF
usage: $scriptname url
Install localy an .xpi addon provided by its url
exemples:
$scriptname https://www.zotero.org/download/connector/dl?browser=firefox&version=5.0.54
$scriptname https://addons.mozilla.org/firefox/downloads/file/1709472/ublock_origin-1.18.6-an+fx.xpi
EOF
}
if [[ $# -ne 1 ]]; then
usage
exit 1
fi
url=$1
tmp="$(mktemp -d)"
echo "Downloading in $tmp ..."
addonfile="$tmp/addons.xpi"
wget -qO "$addonfile" $url
unzip -q -d $tmp $addonfile manifest.json
ID=$(awk -F '"' '/^ +"id":/ {print $4}' "$tmp/manifest.json")
echo "Addon ID: $ID"
firefoxaddonfile=$(ls -d ~/.mozilla/firefox/*.default/)extensions/$ID.xpi
if [[ ! -f "$firefoxaddonfile" ]]; then
mv "$addonfile" "$firefoxaddonfile"
echo "Addon installed at $firefoxaddonfile."
echo "To finalise, desactivate and reactivate it from Firefox."
else
echo "An addons is already there: $firefoxaddonfile. Aborting"
fi
echo "Removing $tmp"
rm -rf $tmp
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment