#!/usr/bin/env bash

USERNAME="cyteen"
PASSWORD="mlpfinsonik"
DISTRIBUTION="ceres"
COMPONENT="main"
ARCH=$(dpkg --print-architecture)
GITEA_URL="https://git2.ring-zero.co.uk/api/packages/${USERNAME}/debian/pool/${DISTRIBUTION}/${COMPONENT}/upload"

# Check if a .deb file was provided as an argument
if [ -z "$1" ]; then
	echo "Usage: $0 <deb_file>"
	exit 1
fi

DEB_FILE="$1"

# Upload the specified .deb file
curl \
	--user ${USERNAME}:${PASSWORD} \
	--upload-file ${DEB_FILE} \
	${GITEA_URL}

echo "See: automate/020_gitea_dpr.sh for sources.list creation."
echo "deb [arch=\${ARCH} signed-by=\${KEYRING}] https://${USERNAME}:${PASSWORD}@https://git2.ring-zero.co.uk/api/packages/${USERNAME}/debian ${DISTRIBUTION} ${COMPONENT}"

# Show available packages
curl -s --url https://cyteen:mlpfinsonik@git2.ring-zero.co.uk/api/v1/packages/cyteen/ |
	jq '.[] | select(.type == "debian") | {type, name, version, html_url, created_at}'
