#!/bin/bash
commandName=gnome-shell-extension-installer;
extensionLocation=/usr/share/gnome-shell/extensions;
contextRoot="$(mktemp -d)";
pushd "$contextRoot" > /dev/null;
sudo apt install -y jq;

wget -O "$commandName" "https://github.com/brunelli/gnome-shell-extension-installer/raw/master/gnome-shell-extension-installer";
sudo install "$commandName" /usr/local/bin;

popd > /dev/null;
rm -rf "$contextRoot";
uuids=();

for id in 779 4907 1162
do
    contextRoot="$(mktemp -d)";
    unzipLocation="$(mktemp -d)";
    pushd "$contextRoot" > /dev/null;

    gnome-shell-extension-installer "$id" --no-install;
    sudo gnome-shell-extension-installer "$id" --yes;
    unzip ./*.zip -d "$unzipLocation";

    uuid="$(jq -r '.uuid' "$unzipLocation/metadata.json")";
    uuids+=("$uuid");

    sudo chmod -R +r "$extensionLocation/$uuid";

    popd > /dev/null;
    rm -rf "$contextRoot";
done

killall -SIGQUIT gnome-shell;
sleep 3;

for uuid in ${uuids[@]}
do
    gnome-extensions enable "$uuid";
done

killall -SIGQUIT gnome-shell;