Search

Gnome Shell - Management of Extensions from console

Contents[Hide]

dropcap-gnome-shell

Under Debian or Ubuntu, Gnome Shell default installation comes with very few extensions.

Hopefully, huge number of extensions are available from Gnome Shell Extensions store.

This store is a fantastic improvment, but you need to install all extensions one by one from the web site.
Till date, there is no official way to install them in console mode.

This is quite annoying if you are a sysadmin and you are handling quite a big amount of workstations, as most of your installation process must be scripted.

This article explains how to install & remove any Gnome Shell extension from https://extensions.gnome.org/ via a console command.

It has been tested under Ubuntu Trusty 14.04 / Gnome Shell 3.8 and Ubuntu Xenial 16.04 / Gnome Shell 3.18.
But it should work on any Ubuntu or Debian flavour and with latest Gnome Shell versions.

1. Step by step Installation

In this section, we will explain in a step-by-step guide how to install or remove a Gnome Shell extension in per user or system wide mode from command line.

If you are not interested in the detailed explainations and you only want a ready-made script to handle everything for you, you can directly jump to All-in-one Installation / removal Script

As an example, we will the Applications Menu extension available from https://extensions.gnome.org/extension/6/applications-menu/.

1.1. Determine Extension ID

If you want to install a Gnome Shell Extension thru command line, first step is to determine the extension ID.

This can be done easily from the Gnome Shell Extensions site. The extension ID is part of the description page URL, just after the /extension/ part.

For example, for Applications Menu extension, as URL is https://extensions.gnome.org/extension/6/applications-menu/, extension ID is 6.

1.2. Get Extension Parameters

Next, you need to get your extension parameters from the Gnome Shell Extension site.

The extension parameters are depending on 2 variables :

  • extension ID
  • Gnome Shell version

The full parameters are available from a URL built-up this way : https://extensions.gnome.org/extension-info/?pk=extension-id&shell_version=version

For example, for Applications Menu extension under Gnome Shell 3.10 you get parameters from URL
https://extensions.gnome.org/extension-info/?pk=6&shell_version=3.10

{"shell_version_map": {"3.18": {"pk": 5320, "version": 29}, "3.3.90": {"pk": 831, "version": 8}, "3.10": {"pk": 3247, "version": 22}, "3.12": {"pk": 3739, "version": 23}, "3.14": {"pk": 4332, "version": 24}, "3.16": {"pk": 4763, "version": 27}, "3.6": {"pk": 2213, "version": 14}, "3.4": {"pk": 1008, "version": 9}, "3.2": {"pk": 284, "version": 5}, "3.8": {"pk": 3216, "version": 21}, "3.21.2": {"pk": 5980, "version": 31}, "3.7.90": {"pk": 2560, "version": 17}, "3.7.92": {"pk": 2640, "version": 18}, "3.15.1": {"pk": 4463, "version": 25}, "3.15.3": {"pk": 4582, "version": 26}, "3.20": {"pk": 5764, "version": 30}, "3.2.1": {"pk": 52, "version": 4}, "3.5.91": {"pk": 1807, "version": 12}, "3.5.90": {"pk": 1736, "version": 11}, "3.5.5": {"pk": 1690, "version": 10}, "3.3.2": {"pk": 33, "version": 3}, "3.2.0": {"pk": 6, "version": 1}, "3.3.4": {"pk": 640, "version": 7}, "3.2.3": {"pk": 284, "version": 5}, "3.7.5": {"pk": 2489, "version": 16}}, "description": "Add a category-based menu for applications.\nThis extension is part of Classic Mode and is officially supported by GNOME. Please do not report bugs using the form below, use GNOME Bugzilla instead.", "creator": "fmuellner", "version_tag": 3247, "name": "Applications Menu", "version": 22, "link": "/extension/6/applications-menu/", "download_url": "/download-extension/apps-menu@gnome-shell-extensions.gcampax.github.com.shell-extension.zip?version_tag=3247", "pk": 6, "creator_url": "/accounts/profile/fmuellner", "icon": "/static/extension-data/icons/icon_6.png", "uuid": "apps-menu@gnome-shell-extensions.gcampax.github.com"}

Important parameters are :

  • name: name of the extension
  • description : description of the extension
  • uuid : extension unique identifier
  • download_url : URL to retrieve the extension archive (zip format)

1.3. Install Extension

Now that you know archive main characteritics (name, URL, UUID, ...), you can download the extension and install it.

Extension is downloaded from the download_url link.

It can be installed at 2 places :

  • on a per-user basis in ~/.local/share/gnome-shell/extensions/extension-uuid/
  • on a system wide basis in /usr/local/share/gnome-shell/extensions/extension-uuid/

1.3.1. Installation per User

To install Applications Menu under Gnome Shell 3.10 on a user basis, we need to run following commands :

Terminal
# wget -O extension.zip "https://extensions.gnome.org/download-extension/apps-menu@gnome-shell-extensions.gcampax.github.com.shell-extension.zip?version_tag=3247"
# mkdir -p "$HOME/.local/share/gnome-shell/extensions/apps-menu@gnome-shell-extensions.gcampax.github.com"
# unzip -op extension.zip -d "$HOME/.local/share/gnome-shell/extensions/apps-menu@gnome-shell-extensions.gcampax.github.com"

Extension will be installed in user space under $HOME/.local/share/gnome-shell/extensions/.

As it is installed in your home directory, you can remove it straight from Gnome Tweak Tool.

gnomeshell extension installed user

1.3.2. Installation System wide

To install the same Applications Menu extension under Gnome Shell 3.10 on a system wide basis, we need to run following commands :

Terminal
# wget -O extension.zip "https://extensions.gnome.org/download-extension/apps-menu@gnome-shell-extensions.gcampax.github.com.shell-extension.zip?version_tag=3247"
# sudo mkdir -p "/usr/local/share/gnome-shell/extensions/apps-menu@gnome-shell-extensions.gcampax.github.com"
# sudo unzip -op extension.zip -d "/usr/local/share/gnome-shell/extensions/apps-menu@gnome-shell-extensions.gcampax.github.com"

Extension will be installed in system wide space under /usr/local/share/gnome-shell/extensions/.

As it is installed in a system directory, you can not remove it straight from Gnome Tweak Tool. It can only be removed as root.

gnomeshell extension installed system

1.4. Uninstall Extension

Under Gnome Shell,  any extension can be removed by simply deleting its installation directory.

If extension has been installed per user, you can remove it with :

Terminal
# rm -f -r $HOME/.local/share/gnome-shell/extensions/apps-menu@gnome-shell-extensions.gcampax.github.com

If extension has been installed system wide, you can remove it with :

Terminal
# sudo rm -f -r /usr/local/share/gnome-shell/extensions/apps-menu@gnome-shell-extensions.gcampax.github.com

1.5. Enable Modification

One you have processed with installation or removal of extensions, last step is to enable these modifications under Gnome Shell.

This can be done easily by restarting Gnome Shell. This can be done from your Gnome Shell environment by typing ALT F2 and then r.

It can also be done via a console with :

Terminal
# gnome-shell --replace &

Don't forget the & at the end of the line.
If you forget it, you will loose your terminal prompt !

2. All-in-one Installation / removal Script

All steps to install/remove a Gnome Shell extension on a per user or system wide basis can be handled by gnomeshell-extension-manage script.

/usr/local/bin/gnomeshell-extension-manage
#!/bin/bash
# --------------------------------------------
# Install extension from Gnome Shell Extensions site
#
# See http://bernaerts.dyndns.org/linux/76-gnome/345-gnome-shell-install-remove-extension-command-line-script
#  for installation instruction
#
# Revision history :
#   13/07/2013 - V1.0 : Creation by N. Bernaerts
#   15/03/2015 - V1.1 : Update thanks to Michele Gazzetti
#   02/10/2015 - V1.2 : Disable wget gzip compression
#   05/07/2016 - V2.0 : Complete rewrite (system path updated thanks to Morgan Read)
#   09/08/2016 - V2.1 : Handle exact or previously available version installation (idea from eddy-geek)
#   09/09/2016 - V2.2 : Switch to gnome-shell to get version [UbuntuGnome 16.04] (thanks to edgard)
#   05/11/2016 - V2.3 : Trim Gnome version and add Fedora compatibility (thanks to Cedric Brandenbourger)
# -------------------------------------------

# check tools availability
command -v unzip >/dev/null 2>&1 || { zenity --error --text="Please install unzip"; exit 1; }
command -v wget >/dev/null 2>&1 || { zenity --error --text="Please install wget"; exit 1; }

# install path (user and system mode)
USER_PATH="$HOME/.local/share/gnome-shell/extensions"
[ -f /etc/debian_version ] && SYSTEM_PATH="/usr/local/share/gnome-shell/extensions" || SYSTEM_PATH="/usr/share/gnome-shell/extensions"

# set gnome shell extension site URL
GNOME_SITE="https://extensions.gnome.org"

# get current gnome version (major and minor only)
GNOME_VERSION="$(DISPLAY=":0" gnome-shell --version | tr -cd "0-9." | cut -d'.' -f1,2)"

# default installation path for default mode (user mode, no need of sudo)
INSTALL_MODE="user"
EXTENSION_PATH="${USER_PATH}"
INSTALL_SUDO=""

# help message if no parameter
if [ ${#} -eq 0 ];
then
    echo "Install/remove extension from Gnome Shell Extensions site https://extensions.gnome.org/"
    echo "Extension ID should be retrieved from https://extensions.gnome.org/extension/<ID>/extension-name/"
    echo "Parameters are :"
    echo "  --install               Install extension (default)"
    echo "  --remove                Remove extension"
    echo "  --user                  Installation/remove in user mode (default)"
    echo "  --system                Installation/remove in system mode"
    echo "  --version <version>     Gnome version (system detected by default)"
    echo "  --extension-id <id>     Extension ID in Gnome Shell Extension site (compulsory)"
    exit 1
fi

# iterate thru parameters
while test ${#} -gt 0
do
  case $1 in
    --install) ACTION="install"; shift; ;;
    --remove) ACTION="remove"; shift; ;;
    --user) INSTALL_MODE="user"; shift; ;;
    --system) INSTALL_MODE="system"; shift; ;;
    --version) shift; GNOME_VERSION="$1"; shift; ;;
    --extension-id) shift; EXTENSION_ID="$1"; shift; ;;
    *) echo "Unknown parameter $1"; shift; ;;
  esac
done

# if no extension id, exit
[ "${EXTENSION_ID}" = "" ] && { echo "You must specify an extension ID"; exit; }

# if no action, exit
[ "${ACTION}" = "" ] && { echo "You must specify an action command (--install or --remove)"; exit; }

# if system mode, set system installation path and sudo mode
[ "${INSTALL_MODE}" = "system" ] && { EXTENSION_PATH="${SYSTEM_PATH}"; INSTALL_SUDO="sudo"; }

# create temporary files
TMP_DESC=$(mktemp -t ext-XXXXXXXX.txt)
TMP_ZIP=$(mktemp -t ext-XXXXXXXX.zip)
TMP_VERSION=$(mktemp -t ext-XXXXXXXX.ver)
rm ${TMP_DESC} ${TMP_ZIP}

# get extension description
wget --quiet --header='Accept-Encoding:none' -O "${TMP_DESC}" "${GNOME_SITE}/extension-info/?pk=${EXTENSION_ID}"

# get extension name
EXTENSION_NAME=$(sed 's/^.*name[\": ]*\([^\"]*\).*$/\1/' "${TMP_DESC}")

# get extension description
EXTENSION_DESCR=$(sed 's/^.*description[\": ]*\([^\"]*\).*$/\1/' "${TMP_DESC}")

# get extension UUID
EXTENSION_UUID=$(sed 's/^.*uuid[\": ]*\([^\"]*\).*$/\1/' "${TMP_DESC}")

# if ID not known
if [ ! -s "${TMP_DESC}" ];
then
  echo "Extension with ID ${EXTENSION_ID} is not available from Gnome Shell Extension site."

# else, if installation mode
elif [ "${ACTION}" = "install" ];
then

  # extract all available versions
  sed "s/\([0-9]*\.[0-9]*[0-9\.]*\)/\n\1/g" "${TMP_DESC}" | grep "pk" | grep "version" | sed "s/^\([0-9\.]*\).*$/\1/" > "${TMP_VERSION}"

  # check if current version is available
  VERSION_AVAILABLE=$(grep "^${GNOME_VERSION}$" "${TMP_VERSION}")

  # if version is not available, get the next one available
  if [ "${VERSION_AVAILABLE}" = "" ]
  then
    echo "${GNOME_VERSION}" >> "${TMP_VERSION}"
    VERSION_AVAILABLE=$(cat "${TMP_VERSION}" | sort -V | sed "1,/${GNOME_VERSION}/d" | head -n 1)
  fi

  # if still no version is available, error message
  if [ "${VERSION_AVAILABLE}" = "" ]
  then
    echo "Gnome Shell version is ${GNOME_VERSION}."
    echo "Extension ${EXTENSION_NAME} is not available for this version."
    echo "Available versions are :"
    sed "s/\([0-9]*\.[0-9]*[0-9\.]*\)/\n\1/g" "${TMP_DESC}" | grep "pk" | grep "version" | sed "s/^\([0-9\.]*\).*$/\1/" | sort -V | xargs

  # else, install extension
  else
    # get extension description
    wget --quiet --header='Accept-Encoding:none' -O "${TMP_DESC}" "${GNOME_SITE}/extension-info/?pk=${EXTENSION_ID}&shell_version=${VERSION_AVAILABLE}"

    # get extension download URL
    EXTENSION_URL=$(sed 's/^.*download_url[\": ]*\([^\"]*\).*$/\1/' "${TMP_DESC}")

    # download extension archive
    wget --quiet --header='Accept-Encoding:none' -O "${TMP_ZIP}" "${GNOME_SITE}${EXTENSION_URL}"

    # unzip extension to installation folder
    ${INSTALL_SUDO} mkdir -p ${EXTENSION_PATH}/${EXTENSION_UUID}
    ${INSTALL_SUDO} unzip -oq "${TMP_ZIP}" -d ${EXTENSION_PATH}/${EXTENSION_UUID}
    ${INSTALL_SUDO} chmod +r ${EXTENSION_PATH}/${EXTENSION_UUID}/*

    # list enabled extensions
    EXTENSION_LIST=$(gsettings get org.gnome.shell enabled-extensions | sed 's/^.\(.*\).$/\1/')

    # if extension not already enabled, declare it
    EXTENSION_ENABLED=$(echo ${EXTENSION_LIST} | grep ${EXTENSION_UUID})
    [ "$EXTENSION_ENABLED" = "" ] && gsettings set org.gnome.shell enabled-extensions "[${EXTENSION_LIST},'${EXTENSION_UUID}']"

    # success message
    echo "Gnome Shell version is ${GNOME_VERSION}."
    echo "Extension ${EXTENSION_NAME} version ${VERSION_AVAILABLE} has been installed in ${INSTALL_MODE} mode (Id ${EXTENSION_ID}, Uuid ${EXTENSION_UUID})"
    echo "Restart Gnome Shell to take effect."

  fi

# else, it is remove mode
else

    # remove extension folder
    ${INSTALL_SUDO} rm -f -r "${EXTENSION_PATH}/${EXTENSION_UUID}"

    # success message
    echo "Extension ${EXTENSION_NAME} has been removed in ${INSTALL_MODE} mode (Id ${EXTENSION_ID}, Uuid ${EXTENSION_UUID})"
    echo "Restart Gnome Shell to take effect."

fi

# remove temporary files
rm -f ${TMP_DESC} ${TMP_ZIP} ${TMP_VERSION}

This script takes few self-explanatory parameters :

Terminal
# gnomeshell-extension-manage
Install/remove extension from Gnome Shell Extensions site https://extensions.gnome.org/
Extension ID should be retrieved from https://extensions.gnome.org/extension/<ID>/extension-name/
Parameters are :
  --install               Install extension (default)
  --remove                Remove extension
  --user                  Installation/remove in user mode (default)
  --system                Installation/remove in system mode
  --version <version>     Gnome version (system detected by default)
  --extension-id <id>     Extension ID in Gnome Shell Extension site (compulsory)

Extension ID is the only compulsory parameters, as others are having default values :

  • default mode is --install and --user
  • default version is your computer detected GnomeShell version

In case the extension ID you ask for is not available from https://extensions.gnome.org/ or if it is not available for your specified GnomeShell version, you'll get an error message.

To install this script, you can directly download it from my Github repository :

Terminal
# sudo wget -O /usr/local/bin/gnomeshell-extension-manage "https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/ubuntugnome/gnomeshell-extension-manage"
# sudo chmod +x /usr/local/bin/gnomeshell-extension-manage

Script is now installed and available to download & install any extension available from Gnome Shell Extensions site.

3. Usage examples

To install Applications Menu under Gnome Shell 3.10 on a user basis :

Terminal
# gnomeshell-extension-manage --install --extension-id 6 --version 3.10 --user
Extension Applications Menu (Id 6, uuid apps-menu@gnome-shell-extensions.gcampax.github.com) is installed in user mode.
Restart Gnome Shell to take effect.

To remove Applications Menu under Gnome Shell 3.10 on a user basis :

Terminal
# gnomeshell-extension-manage --remove --extension-id 6 --user
Extension Applications Menu (Id 6, uuid apps-menu@gnome-shell-extensions.gcampax.github.com) has been removed in user mode.
Restart Gnome Shell to take effect.

To install Applications Menu under Gnome Shell 3.10 on a system wide basis :

Terminal
# gnomeshell-extension-manage --install --extension-id 6 --version 3.10 --system
Extension Applications Menu (Id 6, uuid apps-menu@gnome-shell-extensions.gcampax.github.com) is installed in system mode.
Restart Gnome Shell to take effect.

To remove Applications Menu under Gnome Shell 3.10 on a system wide basis :

Terminal
# gnomeshell-extension-manage --remove --extension-id 6 --system
Extension Applications Menu (Id 6, uuid apps-menu@gnome-shell-extensions.gcampax.github.com) has been removed in system mode.
Restart Gnome Shell to take effect.

 

You are now ready to fully automate your Gnome Shell extensions installation / removal on a per user or system wide basis.

When it comes to productivity gains, Gnome Shell and its extensions really deserve a big Keep It Simple, Stupid ...


Hope it helps.

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus