Files
2026-09-06 13:36:55 +03:00

51 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
: "${NEXSPENCE_URL:?NEXSPENCE_URL is required}"
: "${NEXSPENCE_TOKEN:?NEXSPENCE_TOKEN is required}"
: "${NEXSPENCE_REPOSITORY:?NEXSPENCE_REPOSITORY is required}"
pkg="${1:?package path required}"
repo_name="${NEXSPENCE_REPOSITORY}"
base="${NEXSPENCE_URL%/}/repository/${repo_name}/x86_64"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
cp "$pkg" "$tmp/"
pkg_file="$(basename "$pkg")"
echo "==> Creating Arch repository database"
repo-add --remove "$tmp/${repo_name}.db.tar.zst" "$tmp/$pkg_file"
repo-add --remove "$tmp/${repo_name}.files.tar.zst" "$tmp/$pkg_file"
# Nexspence Raw is HTTP object storage, so symlinks created by repo-add cannot
# be relied upon. Create real .db/.files files as well.
zstd -q -d -c "$tmp/${repo_name}.db.tar.zst" > "$tmp/${repo_name}.db"
zstd -q -d -c "$tmp/${repo_name}.files.tar.zst" > "$tmp/${repo_name}.files"
upload() {
local file="$1"
local remote="$base/$(basename "$file")"
echo "==> PUT $(basename "$file")"
curl --fail-with-body \
--retry 5 \
--retry-all-errors \
--connect-timeout 20 \
--max-time 900 \
-X PUT \
-H "Authorization: Bearer ${NEXSPENCE_TOKEN}" \
--upload-file "$file" \
"$remote"
}
upload "$tmp/$pkg_file"
upload "$tmp/${repo_name}.db"
upload "$tmp/${repo_name}.db.tar.zst"
upload "$tmp/${repo_name}.files"
upload "$tmp/${repo_name}.files.tar.zst"
echo "==> Nexspence publication complete"
echo " ${base}/"