#!/bin/bash

# Spotify
function spotify {
	# Variables
	PACKAGE=spotify-client
	NAME="Spotify"
	show_header 'Begin '$NAME' installation'
	# Check if already installed
	echo 'Checking if '$NAME' is already installed...'
	PKGCHECK=$(dpkg-query -W --showformat='${Status}\n' $PACKAGE|grep "install ok installed")
	if [ "" == "$PKGCHECK" ]; then
		echo $NAME 'is not installed. Proceeding'
		# Add the repository signing key to be able to verify downloaded packages
		show_info 'Adding '$NAME' signing key to keyring...'
		show_warning 'Requires root privileges'
		sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys BBEBDCB318AD50EC6865090613B00F1FD2C19886
		show_success 'Done.'
		# Add the repository
		show_info 'Adding '$NAME' repository to software sources...'
		show_warning 'Requires root privileges'
		echo 'deb http://repository.spotify.com stable non-free' | sudo tee /etc/apt/sources.list.d/spotify.list
		# Update repository information
		show_info 'Updating repository information...'
		sudo apt update -y
		show_success 'Done.'
		# Install
		show_info 'Installing '$NAME'...'
		sudo apt install -y $PACKAGE
		show_success 'Done.'
		whiptail --title "Finished" --msgbox "Installation of $NAME complete." 8 78
		thirdparty
	else
		# Already installed
		show_success $NAME 'already installed.'
		whiptail --title "Finished" --msgbox "$NAME is already installed." 8 78
		thirdparty
	fi
}