# Upstream releases deb files
# https://github.com/ClementTsang/bottom/releases/tag/0.9.6
DEST=${1:-/etc/skel}

GITUSER=zidoro
PROJECT=Pomatez
LATEST_RELEASE_URL="https://api.github.com/repos/${GITUSER}/${PROJECT}/releases/latest"
ARCH=$(dpkg --print-architecture)

# Fetch the latest release tag
TAG=$(torsocks curl -sL -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "${LATEST_RELEASE_URL}" | jq -r '.tag_name')

# Download the.deb file and its SHA256 checksum
# test for ARCH to select the correct file to download
case $ARCH in
amd64)
	EXTENSION="linux-amd64.deb"
	;;
arm64)
	EXTENSION="linux-arm64.deb"
	;;
armhf)
	EXTENSION="linux-armhf.deb"
	;;
*)
	echo "Unable to determine system architecture."
	exit 1
	;;
esac

wget -c -O /tmp/${PROJECT}_${TAG}-1_${EXTENSION} https://github.com/${GITUSER}/${PROJECT}/releases/download/${TAG}/${PROJECT}-${TAG}-${EXTENSION}
# wget -c -O /tmp/${PROJECT}-${TAG}.${EXTENSION}.sha256 https://github.com/${GITUSER}/${PROJECT}/releases/download/${TAG}/${PROJECT}-${TAG}${EXTENSION}.sha256

# Verify the checksum using sha256sum --check
# sha256sum --check /tmp/${PROJECT}-${TAG}.${EXTENSION}.sha256

# If the checksum verification is successful, install the.deb file using dpkg
# if [ $? -eq 0 ]; then
sudo dpkg -i /tmp/${PROJECT}_${TAG}-1_${EXTENSION}
sudo apt-get -f install
# else
#	echo "Checksums do not match. Skipping installation."
#fi
# "Checksums do not match. Skipping installation."
