46 lines
1.7 KiB
Bash
Executable File
46 lines
1.7 KiB
Bash
Executable File
#!/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)}"
|
|
# The Ubuntu releases whose distribution of the repository gets the package, in its component main.
|
|
DISTRIBUTIONS="${DISTRIBUTIONS:-noble resolute}"
|
|
|
|
# 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
|
|
|
|
BODY="$(mktemp)"
|
|
trap 'rm -f "$BODY"' EXIT
|
|
|
|
# Gitea answers 409 for a version that is in the distribution already.
|
|
for DISTRIBUTION in $DISTRIBUTIONS; do
|
|
STATUS="$(curl -s -o "$BODY" -w '%{http_code}' --user "$OWNER:$PACKAGES_TOKEN" \
|
|
--upload-file "$DEB" \
|
|
"$SERVER_URL/api/packages/$OWNER/debian/pool/$DISTRIBUTION/main/upload")"
|
|
case "$STATUS" in
|
|
2??) printf '%s %s is published in %s/main.\n' "$PACKAGE" "$VERSION" "$DISTRIBUTION" ;;
|
|
409) printf '%s %s is already in %s/main, skipping.\n' "$PACKAGE" "$VERSION" "$DISTRIBUTION" ;;
|
|
*) printf 'ERROR: the upload to %s/main returned HTTP %s: %s\n' "$DISTRIBUTION" "$STATUS" "$(cat "$BODY")" >&2; exit 1 ;;
|
|
esac
|
|
done
|