Skip to content

Instantly share code, notes, and snippets.

@Guria
Created June 12, 2023 13:41
Show Gist options
  • Save Guria/6a8b3c420670cdf2ca1c46e0200e010d to your computer and use it in GitHub Desktop.
Save Guria/6a8b3c420670cdf2ca1c46e0200e010d to your computer and use it in GitHub Desktop.
Bash script for Manual Installation of GNOME Extension from ZIP File

GNOME Extension Installer Script

This bash script allows you to manually install GNOME extensions from a ZIP file. It's a helpful tool for installing GNOME extensions from local files rather than using GNOME Extensions or other online sources.

Usage

  1. Save the install_gnome_extension.sh script to your local machine.

  2. Make the script executable:

    chmod +x install_gnome_extension.sh
  3. Run the script, passing the path to your GNOME extension ZIP file as an argument:

    ./install_gnome_extension.sh /path/to/your/extension.zip

Features

  • The script unpacks the provided ZIP file to a temporary directory.
  • It extracts the UUID from the extension's metadata.json file.
  • It checks if an extension with the same UUID is already installed. If so, it halts the installation and notifies you.
  • It creates the necessary directories and installs the extension.
  • Finally, it cleans up the temporary files and gives you instructions on how to enable the extension.

Notes

After running the script, you need to restart GNOME Shell to enable the extension. You can do this by logging out and back in. If you're using an X11 session, you can also press Alt+F2, type r, and then press Enter.

#!/bin/bash
# Check if argument is given
if [ $# -eq 0 ]; then
echo "No arguments provided. Please provide the path to the GNOME extension zip file."
exit 1
fi
# Extension ZIP file path
EXTENSION_ZIP=$1
# Validate if zip file exists
if [ ! -f "$EXTENSION_ZIP" ]; then
echo "File not found! Please provide a valid zip file."
exit 1
fi
# Extension directory
EXTENSION_DIR="$HOME/.local/share/gnome-shell/extensions"
# Temporary directory for unzipping
TEMP_DIR=$(mktemp -d)
# Unzip extension to temporary directory
echo "Unpacking the zip file..."
unzip -q $EXTENSION_ZIP -d $TEMP_DIR
# Get the UUID from metadata.json
echo "Extracting the UUID from metadata.json..."
UUID=$(cat $TEMP_DIR/metadata.json | grep uuid | cut -d \" -f4)
# Check if extension already exists
if [ -d "$EXTENSION_DIR/$UUID" ]; then
echo "Extension with UUID $UUID already exists. Exiting..."
rm -rf $TEMP_DIR
exit 1
fi
# Create extension directory
echo "Creating extension directory..."
mkdir -p $EXTENSION_DIR/$UUID
# Move all files to the extension directory
echo "Installing the extension..."
mv $TEMP_DIR/* $EXTENSION_DIR/$UUID
# Remove the temporary directory
echo "Cleaning up..."
rm -rf $TEMP_DIR
echo "Extension $UUID installed successfully."
echo "Please restart GNOME Shell to enable the extension. You can do this by logging out and back in, or if you're using X11, you can also press Alt+F2, then 'r', then Enter."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment