#!/bin/bash # # Uploads built .deb packages to a Gitea Debian package registry. # # Required env: # DEB_USER - Gitea username (token owner) # DEB_PASS - Gitea access token with the write:package scope # # Optional env (defaults target git.ahax86.ru / owner "pub"): # DEB_REGISTRY - registry base URL # DEB_DISTRIBUTION - apt distribution (default: noble) # DEB_COMPONENT - apt component (default: main) # set -euo pipefail DEB_REGISTRY="${DEB_REGISTRY:-https://git.ahax86.ru/api/packages/pub/debian}" DEB_DISTRIBUTION="${DEB_DISTRIBUTION:-noble}" DEB_COMPONENT="${DEB_COMPONENT:-main}" if [ -z "${DEB_USER:-}" ] || [ -z "${DEB_PASS:-}" ]; then echo "DEB_USER and DEB_PASS must be set" >&2 exit 1 fi upload_url="${DEB_REGISTRY}/pool/${DEB_DISTRIBUTION}/${DEB_COMPONENT}/upload" shopt -s nullglob debs=(*.deb) if [ "${#debs[@]}" -eq 0 ]; then echo "No .deb files found to upload" >&2 exit 1 fi uploaded=0 skipped=0 for file in "${debs[@]}"; do echo "Uploading ${file} -> ${upload_url}" code="$(curl -sS -o /tmp/deb-upload.out -w '%{http_code}' \ --user "${DEB_USER}:${DEB_PASS}" \ --upload-file "./${file}" \ "${upload_url}")" case "$code" in 20*) echo " ok ($code)"; uploaded=$((uploaded + 1)) ;; 409) echo " already published ($code), skipping"; skipped=$((skipped + 1)) ;; *) echo " upload failed (HTTP $code):" >&2; cat /tmp/deb-upload.out >&2; exit 1 ;; esac done echo "Done: ${uploaded} uploaded, ${skipped} already present"