Adds dist.
This commit is contained in:
138
dist/scripts/deploy-apt-repository.sh
vendored
Executable file
138
dist/scripts/deploy-apt-repository.sh
vendored
Executable file
@@ -0,0 +1,138 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# Required environment variables:
|
||||
# APTLY_URL - Aptly server URL (e.g. https://aptly.cloud2.payne.io)
|
||||
# APTLY_PASS - Aptly API password
|
||||
# Optional:
|
||||
# APTLY_USER - API username (default: aptly)
|
||||
# APTLY_GPG_KEY - GPG key fingerprint for signing; if unset, signing is skipped
|
||||
|
||||
APTLY_URL="${APTLY_URL:?APTLY_URL is required}"
|
||||
APTLY_PASS="${APTLY_PASS:?APTLY_PASS is required}"
|
||||
APTLY_USER="${APTLY_USER:-aptly}"
|
||||
APTLY_GPG_KEY="${APTLY_GPG_KEY:-}"
|
||||
|
||||
VERSION=$(cat ../VERSION 2>/dev/null || echo "0.0.0-dev")
|
||||
REPO_NAME="wild-central"
|
||||
DIST="${DIST:-stable}"
|
||||
COMPONENT="main"
|
||||
PACKAGE_DIR="dist/packages"
|
||||
SNAP_NAME="${REPO_NAME}-${VERSION}"
|
||||
AUTH="${APTLY_USER}:${APTLY_PASS}"
|
||||
|
||||
echo "Deploying Wild Central ${VERSION} to APT repository..."
|
||||
echo " URL: ${APTLY_URL}"
|
||||
|
||||
# Signing config
|
||||
if [ -n "$APTLY_GPG_KEY" ]; then
|
||||
SIGNING="{\"GpgKey\":\"${APTLY_GPG_KEY}\"}"
|
||||
else
|
||||
echo "APTLY_GPG_KEY not set — publishing without GPG signature"
|
||||
SIGNING="{\"Skip\":true}"
|
||||
fi
|
||||
|
||||
api() {
|
||||
local METHOD="$1"
|
||||
local ENDPOINT="$2"
|
||||
local DATA="${3:-}"
|
||||
if [ -n "$DATA" ]; then
|
||||
curl -sf --http1.1 -u "$AUTH" -X "$METHOD" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "$DATA" \
|
||||
"${APTLY_URL}/api${ENDPOINT}"
|
||||
else
|
||||
curl -sf --http1.1 -u "$AUTH" -X "$METHOD" "${APTLY_URL}/api${ENDPOINT}"
|
||||
fi
|
||||
}
|
||||
|
||||
# 1. Ensure local repo exists
|
||||
echo ""
|
||||
echo "Ensuring repository '${REPO_NAME}' exists..."
|
||||
if ! api GET "/repos/${REPO_NAME}" > /dev/null 2>&1; then
|
||||
api POST "/repos" \
|
||||
"{\"Name\":\"${REPO_NAME}\",\"DefaultDistribution\":\"${DIST}\",\"DefaultComponent\":\"${COMPONENT}\"}" \
|
||||
> /dev/null
|
||||
echo " Created '${REPO_NAME}'"
|
||||
else
|
||||
echo " '${REPO_NAME}' already exists"
|
||||
fi
|
||||
|
||||
# 2. Upload .deb files
|
||||
echo ""
|
||||
echo "Uploading packages..."
|
||||
UPLOAD_DIR="${REPO_NAME}-${VERSION}"
|
||||
FOUND=0
|
||||
for DEB in "${PACKAGE_DIR}"/wild-central_"${VERSION}"_*.deb; do
|
||||
[ -f "$DEB" ] || continue
|
||||
FOUND=1
|
||||
FILENAME=$(basename "$DEB")
|
||||
echo " ${FILENAME}..."
|
||||
curl -sf --http1.1 -u "$AUTH" -X POST \
|
||||
-F "file=@${DEB}" \
|
||||
"${APTLY_URL}/api/files/${UPLOAD_DIR}" > /dev/null
|
||||
done
|
||||
if [ "$FOUND" -eq 0 ]; then
|
||||
echo "No .deb files found for version ${VERSION} in ${PACKAGE_DIR}"
|
||||
exit 1
|
||||
fi
|
||||
echo " Uploaded"
|
||||
|
||||
# 3. Add packages to repo
|
||||
echo ""
|
||||
echo "Adding packages to '${REPO_NAME}'..."
|
||||
api POST "/repos/${REPO_NAME}/file/${UPLOAD_DIR}" > /dev/null
|
||||
echo " Added"
|
||||
|
||||
# 4. Clean up uploaded files from aptly's staging area
|
||||
api DELETE "/files/${UPLOAD_DIR}" > /dev/null 2>&1 || true
|
||||
|
||||
# 5. Create snapshot for this version
|
||||
echo ""
|
||||
echo "Snapshotting as '${SNAP_NAME}'..."
|
||||
if api GET "/snapshots/${SNAP_NAME}" > /dev/null 2>&1; then
|
||||
echo " Snapshot '${SNAP_NAME}' already exists, using as-is"
|
||||
else
|
||||
api POST "/repos/${REPO_NAME}/snapshots" \
|
||||
"{\"Name\":\"${SNAP_NAME}\",\"Description\":\"Wild Central ${VERSION}\"}" \
|
||||
> /dev/null
|
||||
echo " Snapshot '${SNAP_NAME}' created"
|
||||
fi
|
||||
|
||||
# 6. Publish or update
|
||||
echo ""
|
||||
PUBLISH_PREFIX=$(api GET "/publish" \
|
||||
| jq -r ".[] | select(.Distribution == \"${DIST}\") | .Prefix" 2>/dev/null \
|
||||
| head -1)
|
||||
|
||||
UPDATE_BODY="{\"Snapshots\":[{\"Component\":\"${COMPONENT}\",\"Name\":\"${SNAP_NAME}\"}],\"Signing\":${SIGNING},\"ForceOverwrite\":true}"
|
||||
|
||||
if [ -z "$PUBLISH_PREFIX" ]; then
|
||||
echo "Publishing '${DIST}' for the first time..."
|
||||
api POST "/publish" \
|
||||
"{\"SourceKind\":\"snapshot\",\"Sources\":[{\"Component\":\"${COMPONENT}\",\"Name\":\"${SNAP_NAME}\"}],\"Distribution\":\"${DIST}\",\"Architectures\":[\"amd64\",\"arm64\"],\"Signing\":${SIGNING}}" \
|
||||
> /dev/null
|
||||
else
|
||||
echo "Updating published '${DIST}'..."
|
||||
URL_PREFIX=$(echo "$PUBLISH_PREFIX" | sed 's/^\.$/:/')
|
||||
api PUT "/publish/${URL_PREFIX}/${DIST}" "$UPDATE_BODY" > /dev/null
|
||||
fi
|
||||
echo " Published"
|
||||
|
||||
echo ""
|
||||
echo "Wild Central ${VERSION} is live."
|
||||
echo ""
|
||||
echo "To install on a new device:"
|
||||
echo ""
|
||||
echo " curl -fsSL ${APTLY_URL}/wild-central.gpg \\"
|
||||
echo " | sudo tee /usr/share/keyrings/wild-central.gpg > /dev/null"
|
||||
echo ""
|
||||
echo " sudo tee /etc/apt/sources.list.d/wild-central.sources <<EOF"
|
||||
echo " Types: deb"
|
||||
echo " URIs: ${APTLY_URL}"
|
||||
echo " Suites: ${DIST}"
|
||||
echo " Components: ${COMPONENT}"
|
||||
echo " Signed-By: /usr/share/keyrings/wild-central.gpg"
|
||||
echo " EOF"
|
||||
echo ""
|
||||
echo " sudo apt update && sudo apt install wild-central"
|
||||
Reference in New Issue
Block a user