Last active
August 29, 2015 14:09
-
-
Save prurigro/295c023e3102ffa22fb8 to your computer and use it in GitHub Desktop.
(Gnome 3) Gnome Extension Downloader: A script that takes an extension's ID # or URL and downloads a .zip containing the latest version of that extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# gnome-dlext - a gnome extension download tool | |
# | |
# instructions: | |
# 1. find the url of the extension you wish to download on extensions.gnome.org | |
# 2. run this script with either the extension url, or the id number contained in it | |
# 3. if there are no errors, your extension should then be downloaded! | |
# | |
# note: other extension servers can be used by editing GNOME_EXTENSIONS_DOMAIN below | |
# | |
# written by: Kevin MacMartin <[email protected]> | |
# released under the MIT license (http://opensource.org/licenses/MIT) | |
# | |
# set this to the domain (no http:// or trailing slash) of the extension server | |
GNOME_EXTENSIONS_DOMAIN='extensions.gnome.org' | |
# Simple function to display an error and quit | |
function error_quit() { | |
echo "Error: $1" | |
exit 1 | |
} | |
[[ ! $(type -P wget) ]] && error_quit "wget must be installed to run this script" | |
[[ ! $(type -P gnome-shell) ]] && error_quit "gnome-shell must be installed to run this script" | |
# Extract the gnome shell version from the output of 'gnome-shell --version' | |
GNOME_SHELL_VERSION=$(gnome-shell --version | sed 's|^.* ||' | grep -o -e '^[0-9][0-9]*\.[0-9][0-9]*') | |
# Display usage information if not input is received | |
[[ -z "$1" ]] \ | |
&& echo "Usage: $(grep -o -e "[^\/]*$" <<< "$0") [extension-id|extension-url] : download the requested extension" \ | |
&& exit 0 | |
# Parse the argument provided by the user for the extension id | |
EXTENSION_ID=$(grep -o -e '[0-9]*' <<< "$1" | head -n 1) | |
# Fail if an extension id couldn't be parsed | |
[[ -z "$EXTENSION_ID" ]] \ | |
&& error_quit "$1 is not a valid extension id or url" | |
# Use the extension id to query the extension server for the download URL | |
DOWNLOAD_URL=$(wget -T 1 -t 1 -qO- 'https://'$GNOME_EXTENSIONS_DOMAIN'/extension-info/?pk='$EXTENSION_ID'&shell_version='$GNOME_SHELL_VERSION \ | |
| grep -o -e '"download_url": "[^"]*"' \ | |
| sed 's|"download_url": "|https://'$GNOME_EXTENSIONS_DOMAIN'|;s|"$||') | |
# Fail if a download URL couldn't be parsed | |
[[ -z "$DOWNLOAD_URL" ]] \ | |
&& error_quit "no response from server\n" | |
# Parse the download URL for the filename of the download | |
DOWNLOAD_FILENAME=$(sed 's|^.*/||;s|\.zip.*$|\.zip|' <<< "$DOWNLOAD_URL") | |
# Fail if the file already exists | |
[[ -f "$DOWNLOAD_FILENAME" ]] \ | |
&& error_quit "$DOWNLOAD_FILENAME already exists" | |
# Download the url we grabbed and save it as the filename we parsed | |
wget "$DOWNLOAD_URL" -O "$DOWNLOAD_FILENAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment