#!/usr/bin/env bash
# sudo apt install -y kodi

#
# 18.04  bionic     buster
# 17.10  artful     stretch

PROJECT="team-xbmc"
PROJECT_URL="https://launchpad.net/~"${PROJECT}"/+archive/ubuntu/ppa"
PROJECT_PAGE="$(curl -sS "${PROJECT_URL}")"
KEY_LINK_XPATH='string(//*[@id="signing-key"]/dd[1]/a[1]/@href)'
KEY_LINK="$(echo "${PROJECT_PAGE}" | xmllint --html --xpath "${KEY_LINK_XPATH}" - 2>/dev/null)"
FINGERPRINT_XPATH='string(//*[@id="signing-key"]/dd[1]/a[1]/code)'
FINGERPRINT="$(echo "${PROJECT_PAGE}" | xmllint --html --xpath "${FINGERPRINT_XPATH}" - 2>/dev/null)"

KEY_ID_XPATH='string(//*[@id="signing-key"]/dd[2])'
KEY_ID="$(echo "${PROJECT_PAGE}" | xmllint --html --xpath "${KEY_ID_XPATH}" - 2>/dev/null)"

# Download the key
KEY_SERVER="keyserver.ubuntu.com"
KEY_DIR="/etc/apt/trusted.gpg.d/
SIGNED_BY="${KEY_DIR}/${PROJECT}.gpg"

sudo gpg --homedir /tmp --no-default-keyring --keyring "${SIGNED_BY}" --keyserver "${KEY_SERVER}" --recv-keys "${KEY_ID}

RELEASE="mantic"

sudo echo "deb [signed-by=${SIGNED_BY}] http://ppa.launchpad.net/${PROJECT}/ppa/ubuntu ${RELEASE} main" >/etc/apt/sources.list-available${PROJECT}.list
sudo echo "deb-src [signed-by=${SIGNED_BY}] http://ppa.launchpad.net/${PROJECT}/ppa/ubuntu ${RELEASE} main" >>/etc/apt/sources.list-available/${PROJECT}.list

sudo ln -sf /etc/apt/sources.list-available/${PROJECT}.list /etc/apt/sources.list.d/${PROJECT}.list

sudo apt update

# Plugins
#covenant
#sanctuary http://sanctuaryrepo.esy.es/sanc/
#neptune rising  http://repo.mrblamo.xyz/
#placenta
#sports devil
#incursion
#poseidon
#genesis reborn
#uranus
#maverick tv

packages="                                                   \
    ca-certificates                                          \
    kodi=2:18.*                                              \
    kodi-eventclients-kodi-send                              \
    kodi-pvr-argustv                                         \
    kodi-pvr-dvbviewer                                       \
    kodi-pvr-hdhomerun                                       \
    kodi-pvr-hts                                             \
    kodi-pvr-iptvsimple                                      \
    kodi-pvr-mediaportal-tvserver                            \
    kodi-pvr-mythtv                                          \
    kodi-pvr-nextpvr                                         \
    kodi-pvr-njoy                                            \
    kodi-pvr-vdr-vnsi                                        \
    kodi-pvr-vuplus                                          \
    kodi-pvr-wmc                                             \
    kodi-eventclients-wiiremote                              \
    kodi-repository-kodi                                     \
    vdr                                                      \
    vdr-plugin-vnsiserver                                    \
    tzdata"

packages_missing="                                           \    
    kodi-game-libretro                                       \
    kodi-inputstream-rtmp                                    \
    kodi-inputstream-adaptive                                \
    kodi-peripheral-joystick                                 \
    kodi-pvr-dvblink                                         \
    kodi-pvr-filmon                                          \
    kodi-pvr-octonet                                         \
    kodi-pvr-pctv                                            \
    kodi-pvr-stalker                                         \
    kodi-pvr-teleboy                                         \
    kodi-pvr-vbox                                            \
    kodi-pvr-zattoo"

sudo apt update &&
	sudo apt install -y --no-install-recommends $packages
sudo apt install -y --no-install-recommends $packages_missing
sudo apt install -y --no-install-recommends
