#!/bin/bash
#
# Publish a .deb file to the arkana APT repository.
#
# Runs on arkana-1 as the "arkana" user (or whoever owns /var/www/apt).
# Used by CI workflows after they build + upload a .deb to /tmp/.
#
# Usage:
#   ./publish.sh /path/to/package_1.2.3_arm64.deb

set -euo pipefail

DEB_FILE="$1"
REPO_DIR="/var/www/apt"
SUITE="stable"

if [ ! -f "$DEB_FILE" ]; then
    echo "ERROR: file not found: $DEB_FILE" >&2
    exit 1
fi

echo "==> Publishing $DEB_FILE to $REPO_DIR ($SUITE)"
reprepro -b "$REPO_DIR" includedeb "$SUITE" "$DEB_FILE"
echo "==> Current $SUITE packages:"
reprepro -b "$REPO_DIR" list "$SUITE"
