#!/bin/sh set -e # Apple container CLI on macOS, Docker CE on Linux. case "$(uname -s)" in Darwin) CONTAINER_RUNTIME=container ;; Linux) CONTAINER_RUNTIME=docker ;; *) printf 'ERROR: unsupported platform %s\n' "$(uname -s)" >&2; exit 1 ;; esac OWNER="${OWNER:-slawek}" SERVER_URL="${SERVER_URL:-https://gitea.koszewscy.waw.pl}" PACKAGES_TOKEN="${PACKAGES_TOKEN:-$(cat ~/.gitea-packages-token)}" # Reads the changelog copied into the builder image, so no bind mount is needed. changelog_field() { $CONTAINER_RUNTIME run --rm vpn-router-builder \ dpkg-parsechangelog --show-field "$1" -l /build/src/debian/changelog } VERSION="$(changelog_field Version)" PACKAGE="$(changelog_field Source)" DEB="out/${PACKAGE}_${VERSION}_all.deb" if [ ! -f "$DEB" ]; then printf 'ERROR: %s does not exist. Run ./build.sh first.\n' "$DEB" >&2 exit 1 fi STATUS="$(curl -s -o /dev/null -w '%{http_code}' --user "$OWNER:$PACKAGES_TOKEN" \ "$SERVER_URL/api/v1/packages/$OWNER/debian/$PACKAGE/$VERSION")" case "$STATUS" in 200) printf '%s %s is already published, skipping.\n' "$PACKAGE" "$VERSION"; exit 0 ;; 404) ;; *) printf 'ERROR: version check returned HTTP %s.\n' "$STATUS" >&2; exit 1 ;; esac curl --fail-with-body --user "$OWNER:$PACKAGES_TOKEN" \ --upload-file "$DEB" \ "$SERVER_URL/api/packages/$OWNER/debian/pool/noble/main/upload"