#!/bin/bash

# Some color definitions
gry=`tput setaf 8`
red=`tput setaf 1`
rst=`tput sgr 0`

echo "${gry}INFO: Ubuntu version we're running:${rst}"
lsb_release -r|cut -f2
echo "${gry}INFO: Installed Eddie version:${rst}"
eddie-ui --cli --version || echo "${red}ERROR: Couldn't execute eddie-ui, not installed apparently, continuing…${rst}"

echo "${gry}INFO: Removing any old versions of the AirVPN client…${rst}"
sudo apt-get -qy remove airvpn || echo "${red}ERROR: Old Eddie versions are not installed, continuing…${rst}";
sudo apt-get -qy remove eddie-ui || echo "${red}ERROR: eddie-ui is not installed, continuing…${rst}";

echo "${gry}INFO: Doing a quick cleanup of old, unneeded packages…${rst}"
sudo apt-get -qy autoremove && sudo apt-get -qy autoclean

echo "${gry}INFO: Trying to install Eddie-UI, the safe way…${rst}"
wget -qO - "https://eddie.website/repository/keys/eddie_maintainer_gpg.key"|sudo apt-key add - || echo "${red}ERROR: Error occured when adding PGP key, exiting…${rst}"; exit 1;
sudo echo "deb http://eddie.website/repository/apt stable main" > /etc/apt/sources.list.d/eddie.website.list || echo "${red}ERROR: Error occured when adding the Eddie repository, exiting…${rst}"; exit 1;
sudo apt-get -qy update || echo "${red}ERROR: Error occured when trying to update the package cache, exiting…${rst}"; exit 1;
sudo apt-get -qy install mono-complete eddie-ui || echo "${red}ERROR: Error occured when trying to install Eddie, exiting…${rst}"; exit 1;
tput sgr 0
exit 0
