#!/bin/bash

version=3.10

install_packages gettext gsettings-desktop-schemas make pandoc gir1.2-keybinder-3.0 gir1.2-notify-0.7 gir1.2-vte-2.91 gir1.2-wnck-3.0 libkeybinder-3.0-0 libutempter0 python3 python3-pip python3-cairo python3-dbus python3-gi python3-pbr libgirepository1.0-dev || exit 1
if package_is_new_enough python3-setuptools 56.0.0 ;then
  install_packages python3-importlib-metadata || exit 1
else
  install_packages python3-pip || exit 1
  sudo -H python3 -m pip install importlib-metadata "setuptools>=56" || error "pip failed to install required dependencies"
  hash -r
fi

git_clone https://github.com/Guake/guake -b ${version} || error 'Failed to clone repository!'
cd ~/guake || error "Failed to enter the $HOME/guake folder! Most likely this means the repository failed to download."
make -j2 || error "The 'make' command failed to setup locales and generate desktop files!"
status "Installing Guake Terminal"
sudo make install || error "The 'make' command was unable to install Guake!"

sudo rm -rf ~/guake

status "Making Guake Terminal run on startup"
sudo cp /usr/local/share/guake/autostart-guake.desktop /etc/xdg/autostart-guake.desktop

status "Running guake in background"
setsid guake &>/dev/null &
