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

# 18.04  bionic     buster
# 17.10  artful     stretch


PROJECT="kisak-mesa"
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)"

# set arch
ARCH=$(dpkg --print-architecture)

# 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 [arch=${ARCH} signed-by=${SIGNED_BY}] http://ppa.launchpad.net/${PROJECT}/ppa/ubuntu ${RELEASE} main" > /etc/apt/sources.list-available/${PROJECT}.list
sudo echo "deb-src [arch=${ARCH} 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


packages=" \
  mesa-vulkan-drivers \
  libgl1-mesa-dri \
  libglx-mesa0  \
  glmark2 \
  tzdata \
"

packages_missing=""

sudo apt install -y --no-install-recommends $packages 
# sudo apt install -y --no-install-recommends $packages_missing
# sudo apt install -y --no-install-recommends 
