#!/usr/bin/env bash # publish.sh — put a built release on sl0ppi.sl0p.foo. # # packaging/publish.sh [--host root@sl0p.foo] [--dry-run] # # Publishing is deliberately dumb: rsync a rendered site plus the artifact, then # ask the live site whether it agrees. There is no CI and no build on the box — # the tarball must already exist (`make package`). # # The vhost lives in the sl0pday repo (nginx/sl0p.conf, deployed with its own # ./deploy.sh). This script only ships content into /opt/sl0ppi/www. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" HOST="${SL0PPI_PUBLISH_HOST:-root@sl0p.foo}" REMOTE_DIR="/opt/sl0ppi/www" BASE_URL="https://sl0ppi.sl0p.foo" dry_run=0 while [ $# -gt 0 ]; do case "$1" in --host) HOST="$2"; shift 2 ;; --host=*) HOST="${1#*=}"; shift ;; -n|--dry-run) dry_run=1; shift ;; -h|--help) sed -n '2,12p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; *) echo "publish.sh: unknown argument '$1'" >&2; exit 2 ;; esac done log() { printf '\033[36m==>\033[0m %s\n' "$*"; } die() { printf '\033[31merror:\033[0m %s\n' "$*" >&2; exit 1; } run() { if [ "$dry_run" = 1 ]; then echo " would: $*"; else "$@"; fi; } VERSION="$(cat "$ROOT/VERSION")" STEM="sl0ppi-$VERSION-x86_64-linux" ARTIFACT="$STEM.tar.gz" OUT="$ROOT/packaging/out" [ -f "$OUT/$ARTIFACT" ] || die "no $OUT/$ARTIFACT — run 'make package' first" [ -f "$OUT/$ARTIFACT.sha256" ] || die "no checksum beside the artifact" # Trust nothing: recompute rather than believing the sidecar we are about to # publish as authoritative. SHA="$(sha256sum "$OUT/$ARTIFACT" | cut -d' ' -f1)" SIDECAR="$(cut -d' ' -f1 < "$OUT/$ARTIFACT.sha256")" [ "$SHA" = "$SIDECAR" ] || die "artifact does not match its .sha256 sidecar" # Refuse to overwrite a published version with different bytes: released URLs are # immutable (nginx caches /releases/ for a year), so republishing a changed file # under the same name would serve two different things to different people. remote_sha="$(ssh -o BatchMode=yes "$HOST" \ "sha256sum $REMOTE_DIR/releases/$ARTIFACT 2>/dev/null | cut -d' ' -f1" || true)" if [ -n "$remote_sha" ] && [ "$remote_sha" != "$SHA" ]; then die "$ARTIFACT is already published with a DIFFERENT checksum published $remote_sha local $SHA Bump VERSION instead of rewriting a release." fi # --- render the site ------------------------------------------------------- STAGE="$(mktemp -d "${TMPDIR:-/tmp}/sl0ppi-publish.XXXXXX")" trap 'rm -rf "$STAGE"' EXIT mkdir -p "$STAGE/releases" DATE="$(date -u +%Y-%m-%d)" MANIFEST="$ROOT/packaging/stage/$STEM/MANIFEST" components="" if [ -f "$MANIFEST" ]; then while read -r name version; do [ -n "$name" ] || continue components+="