Last active
January 31, 2019 16:54
-
-
Save fieldse/69988f715921e106ed83083d429ecf09 to your computer and use it in GitHub Desktop.
GNOME utility: Install gnome-shell plugins from zip file commandline
This file contains 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
#!/bin/bash | |
# gnome-shell-install | |
# Utility script to install gnome-shell plugin from zip | |
## Usage: | |
# Copy this file to your .local/bin directory and chmod +x [filename] | |
# From the directory where your downloaded GNOME shell plugin zip is, run | |
# gnome-plugin-install.sh [mypluginfilename.zip] | |
# License: | |
# Free / Unlicensed. Use it how you want. | |
# Warning: This could break your machine or blow up your house. | |
# Read it before using, and make sure the code is safe first. | |
# By using this script, you agree that you bear 100% responsibility for any consequential results. | |
ARGV=$@ | |
function usage() { | |
echo "Usage: " | |
echo "$0: [filename]" | |
echo "Params:" | |
echo " filename: Gnome shell extension zip file" | |
} | |
# Check args length | |
function checkargs() { | |
if [[ $# -ne 1 ]]; then | |
echo "Error: pass filename of zip as argument" | |
usage | |
exit 1 | |
fi | |
} | |
function get_filename() { | |
checkargs $ARGV && echo "$ARGV" || exit 1 | |
} | |
function get_ext_name() { | |
fname="$1" | |
if [[ -z "$fname" ]] ; then | |
echo "filename ${fname} not valid length" | |
fi | |
extname="$(unzip -c $fname metadata.json | grep uuid | cut -d \" -f4)" | |
echo "$extname" | |
} | |
function file_exists(){ | |
[[ -f "$1" ]] && return 0 || return 1 | |
} | |
function makedir(){ | |
if [[ ! -d "$1" ]] ; then | |
printf "\ncreating dir $1" | |
mkdir -p "$1" | |
if [[ ! $? ]] ; then | |
echo "Create dir failed" | |
exit 1 | |
fi | |
else | |
printf "dir exists" | |
fi | |
} | |
function install_ext() { | |
if [[ $# -ne 2 ]] ; then | |
echo "Error: must pass filename and extname to install_ext" | |
exit 1 | |
fi | |
fname="$1" | |
extname="$2" | |
install_dir="$HOME/.local/share/gnome-shell/extensions/$extname" | |
# echo -e "\nfilename: \t$fname" | |
# echo -e "extname: \t$extname" | |
echo -e "\nInstalling extension to $install_dir..." | |
# Create install dir | |
echo -e "\nCreate dir..." | |
makedir "$install_dir" | |
# Unzip | |
echo -e "\nUnzipping..." | |
unzip -q "$fname" -d "$install_dir" && echo "OK" || exit 1 | |
# Enable plugin | |
echo -e "\nEnabling plugin..." | |
gnome-shell-extension-tool -e "$extname" | |
[[ $? ]] && echo "plugin installed successfully" || echo "Install failed" | |
} | |
function main() { | |
echo -e "\n################### Installing gnome extension ################\n" | |
filename="$(get_filename $ARGV)" | |
extension_name="$(get_ext_name $filename)" | |
install_ext "$filename" "$extension_name" | |
} | |
# Run | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script to install gnome-shell plugins from ZIP at commandline.
Tags:
GNOME, Gnome shell, linux, BASH, zip