feat: gnome-extensions module (#190)

This commit is contained in:
fiftydinar 2024-04-10 19:17:15 +02:00 committed by GitHub
commit a53ae7d91c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 122 additions and 0 deletions

View file

@ -0,0 +1,30 @@
# `gnome-extensions`
The `gnome-extensions` module can be used to install Gnome extensions inside system directory.
This module is universally compatible with all distributions which ship Gnome, as it's not tied to specific distribution packaging format for installing extensions.
Almost all Gnome extensions are compatible for installation.
Thanks to https://extensions.gnome.org which provides releases of extensions as zips, it is very easy to maintain this module configuration.
The only maintenance is to bump the extension version when new Fedora/Gnome releases (around every 6 months).
What does this module do?
- It parses the extension input from module recipe file, which is part of the download URL
- It downloads the extension directly from https://extensions.gnome.org
- Downloaded extension archive is then extracted to temporary directory
- All of its extracted files are copied to the appropriate final directories
(`/usr/share/gnome-shell/extensions`, `/usr/share/glib-2.0/schemas`, & `/usr/share/locale`)
# Usage
How to install extensions using the module:
1. Go to https://extensions.gnome.org
2. Search for the extension that you want to install and open its extension page
3. Select the correct GNOME shell version & extension version from the dropdown
- The command `gnome-shell --version` can be used to get the GNOME version of a running system.
4. When the download dialog for the extension comes up, copy everything but the `.shell-extension.zip` suffix from the filename into the `install:` array in this module's configuration.
An extension might need additional system dependencies in order to function.
In that case, you should install the required dependencies before the `gnome-extensions` module is ran.
Information about the required dependencies (if any) are usually on the extension's page.

View file

@ -0,0 +1,85 @@
#!/usr/bin/env bash
# Tell build process to exit if there are any errors.
set -euo pipefail
get_yaml_array GETTEXT_DOMAIN '.install[]' "$1"
GNOME_VER=$(gnome-shell --version | sed 's/[^0-9]*\([0-9]*\).*/\1/')
echo "Gnome version: v${GNOME_VER}"
if [[ ${#GETTEXT_DOMAIN[@]} -gt 0 ]]; then
for EXTENSION in "${GETTEXT_DOMAIN[@]}"; do
URL="https://extensions.gnome.org/extension-data/${EXTENSION}.shell-extension.zip"
TMP_DIR="/tmp/${EXTENSION}"
ARCHIVE=$(basename "${URL}")
ARCHIVE_DIR="${TMP_DIR}/${ARCHIVE}"
VERSION=$(echo "${EXTENSION}" | grep -oP 'v\d+')
echo "Installing ${EXTENSION} Gnome extension with version ${VERSION}"
# Download archive
curl -L "${URL}" --create-dirs -o "${ARCHIVE_DIR}"
# Extract archive
echo "Extracting ZIP archive"
unzip "${ARCHIVE_DIR}" -d "${TMP_DIR}" > /dev/null
# Remove archive
echo "Removing archive"
rm "${ARCHIVE_DIR}"
# Read necessary info from metadata.json
echo "Reading necessary info from metadata.json"
EXTENSION_NAME=$(yq '.name' < "${TMP_DIR}/metadata.json")
UUID=$(yq '.uuid' < "${TMP_DIR}/metadata.json")
EXT_GNOME_VER=$(yq '.shell-version[]' < "${TMP_DIR}/metadata.json")
# If extension does not have the important key in metadata.json,
# inform the user & fail the build
if [[ "${UUID}" == "null" ]]; then
echo "ERROR: Extension '${EXTENSION_NAME}' doesn't have 'uuid' key inside metadata.json"
echo "You may inform the extension developer about this error, as he can fix it"
exit 1
fi
if [[ "${EXT_GNOME_VER}" == "null" ]]; then
echo "ERROR: Extension '${EXTENSION_NAME}' doesn't have 'shell-version' key inside metadata.json"
echo "You may inform the extension developer about this error, as he can fix it"
exit 1
fi
# Compare if extension is compatible with current Gnome version
# If extension is not compatible, inform the user & fail the build
if ! [[ "${EXT_GNOME_VER}" =~ "${GNOME_VER}" ]]; then
echo "ERROR: Extension '${EXTENSION_NAME}' is not compatible with current Gnome v${GNOME_VER}!"
exit 1
fi
# Install main extension files
echo "Installing main extension files"
install -d -m 0755 "/usr/share/gnome-shell/extensions/${UUID}/"
find "${TMP_DIR}" -mindepth 1 -maxdepth 1 ! -path "*locale*" ! -path "*schemas*" -exec cp -r {} "/usr/share/gnome-shell/extensions/${UUID}/" \;
find "/usr/share/gnome-shell/extensions/${UUID}" -type d -exec chmod 0755 {} +
find "/usr/share/gnome-shell/extensions/${UUID}" -type f -exec chmod 0644 {} +
# Install schema
if [[ -d "${TMP_DIR}/schemas" ]]; then
echo "Installing schema extension file"
install -d -m 0755 "/usr/share/glib-2.0/schemas/"
install -D -p -m 0644 "${TMP_DIR}/schemas/"*.gschema.xml "/usr/share/glib-2.0/schemas/"
else
echo "ERROR: Extension '${EXTENSION_NAME}' doesn't supply crucial gschema.xml file."
echo " Please contact extension developer about this issue."
exit 1
fi
# Install languages
# Locale is not crucial for extensions to work, as they will fallback to gschema.xml
# Some of them might not have any locale at the moment
# So that's why I made a check for directory
if [[ -d "${TMP_DIR}/locale" ]]; then
echo "Installing language extension files"
install -d -m 0755 "/usr/share/locale/"
cp -r "${TMP_DIR}/locale"/* "/usr/share/locale/"
fi
# Delete the temporary directory
echo "Cleaning up the temporary directory"
rm -r "${TMP_DIR}"
echo "Extension '${EXTENSION_NAME}' is successfully installed"
echo "----------------------------------DONE----------------------------------"
done
else
echo "ERROR: You did not specify the extension to install in module recipe file"
exit 1
fi
echo "Finished the installation of Gnome extensions"

View file

@ -0,0 +1,7 @@
name: gnome-extensions
shortdesc: The gnome-extensions module can be used to install Gnome extensions inside system directory.
readme: https://raw.githubusercontent.com/blue-build/modules/main/modules/gnome-extensions/README.md
example: |
type: gnome-extensions
install:
- nightthemeswitcherromainvigier.fr.v75