# https://launchpad.net/~mkusb/+archive/ubuntu/ppa

PROJECT="mkusb"
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/keyrings"
SIGNED_BY="${KEY_DIR}/${PROJECT}.gpg"
# sudo gpg --homedir /tmp --no-default-keyring --keyring "${SIGNED_BY}" --keyserver "${KEY_SERVER}" --recv-keys "${KEY_ID}

echo "PROJECT: $PROJECT"
echo "PROJECT_URL: $PROJECT_URL"
# echo "PROJECT_PAGE: $PROJECT_PAGE"
echo "KEY_LINK_XPATH: $KEY_LINK_XPATH"
echo "KEY_LINK: $KEY_LINK"
echo "FINGERPRINT_XPATH: $FINGERPRINT_XPATH"
echo "FINGERPRINT: $FINGERPRINT"

echo "KEY_ID_XPATH: $KEY_ID_XPATH"
echo "KEY_ID: $KEY_ID"

echo "KEY_SERVER: $KEY_SERVER"
echo "KEY_DIR: $KEY_DIR"
echo "SIGNED_BY: $SIGNED_BY"


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

