interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / infra / spark / forgejo / forgejo-runtime-restore.sh
| 1 | #!/usr/bin/env bash |
| 2 | # infra/spark/forgejo/forgejo-runtime-restore.sh: put back the Forgejo + gocryptfs binaries that |
| 3 | # atlas-forgejo.service and atlas-forgejo-storage.service exec through the symlink |
| 4 | # ~/atlas-forgejo-setup-20260904 (its target under ~/archive/historical-experiments-pre-omarchy |
| 5 | # was deleted 2026-11-08; see EVIDENCE-20261109.txt). |
| 6 | # |
| 7 | # Sources (read-only; the atlas account's copy of the same Sept 4 setup dir): |
| 8 | # /home/atlas/atlas-forgejo-setup-20260904/forgejo-16.0.3-linux-arm64 (+ .asc, binary-proof.json, gnupg/pubring.kbx) |
| 9 | # /home/atlas/atlas-forgejo-setup-20260904/packages/gocryptfs_2.4.0-1ubuntu0.24.04.3_arm64.deb |
| 10 | # Checks: forgejo sha256 == binary-proof.json; detached signature good for the key named there |
| 11 | # (scratch GNUPGHOME holding only a copy of the public keyring); deb sha256 == the SHA256 in the |
| 12 | # signed Ubuntu index (apt-cache show); both binaries run --version / -version. |
| 13 | # |
| 14 | # Usage: forgejo-runtime-restore.sh --dry-run [SCRATCH] stage + verify into SCRATCH (default mktemp); no live change |
| 15 | # forgejo-runtime-restore.sh --apply stage + verify into TARGET, then repoint the symlink |
| 16 | # --apply is a LIVE change: within seconds the restart-looping system unit atlas-forgejo-storage |
| 17 | # finds its binary and mounts ~/atlas-forgejo/data; atlas-forgejo.service then still needs |
| 18 | # `sudo systemctl start atlas-forgejo.service` (root: Drake or the desk). Rollback: |
| 19 | # ln -sfn "$(cat TARGET/previous-symlink-target)" ~/atlas-forgejo-setup-20260904 |
| 20 | # Env: SRC (default above), TARGET (default ~/.local/opt/atlas-forgejo-runtime-20260904), |
| 21 | # LINK (default ~/atlas-forgejo-setup-20260904) |
| 22 | # Host tools: sha256sum, gpg, dpkg-deb, apt-cache. Omega replacement: none; this is recovery of |
| 23 | # foreign binaries whose retirement is Drake's restore-or-retire decision (infra/RUNBOOK.md). |
| 24 | set -euo pipefail |
| 25 | umask 022 |
| 26 | SRC=${SRC:-/home/atlas/atlas-forgejo-setup-20260904} |
| 27 | TARGET=${TARGET:-$HOME/.local/opt/atlas-forgejo-runtime-20260904} |
| 28 | LINK=${LINK:-$HOME/atlas-forgejo-setup-20260904} |
| 29 | BIN=forgejo-16.0.3-linux-arm64 |
| 30 | DEB=gocryptfs_2.4.0-1ubuntu0.24.04.3_arm64.deb |
| 31 | |
| 32 | mode=${1:-} |
| 33 | case $mode in |
| 34 | --dry-run) stage=${2:-$(mktemp -d -t forgejo-runtime.XXXXXX)} ;; |
| 35 | --apply) stage=$TARGET ;; |
| 36 | *) echo "usage: forgejo-runtime-restore.sh --dry-run [SCRATCH] | --apply" >&2; exit 2 ;; |
| 37 | esac |
| 38 | die() { echo "forgejo-runtime-restore: $*" >&2; exit 1; } |
| 39 | |
| 40 | [ -f "$SRC/$BIN" ] && [ -f "$SRC/packages/$DEB" ] && [ -f "$SRC/binary-proof.json" ] || die "source files missing under $SRC" |
| 41 | mkdir -p "$stage/runtime" |
| 42 | [ -z "$(ls -A "$stage/runtime")" ] || die "$stage/runtime is not empty; refusing to overwrite" |
| 43 | |
| 44 | want=$(sed -n 's/.*"sha256": *"\([0-9a-f]*\)".*/\1/p' "$SRC/binary-proof.json") |
| 45 | key=$(sed -n 's/.*"signingKey": *"\([0-9A-F]*\)".*/\1/p' "$SRC/binary-proof.json") |
| 46 | install -m 755 "$SRC/$BIN" "$stage/$BIN" |
| 47 | got=$(sha256sum "$stage/$BIN" | cut -d' ' -f1) |
| 48 | [ "$got" = "$want" ] || die "forgejo sha256 $got != binary-proof.json $want" |
| 49 | echo "forgejo sha256: ok $got (binary-proof.json)" |
| 50 | |
| 51 | gh=$(mktemp -d); trap 'rm -rf "$gh"' EXIT |
| 52 | cp "$SRC/gnupg/pubring.kbx" "$gh/" # public keyring only, never private-keys-v1.d |
| 53 | if out=$(GNUPGHOME=$gh gpg --batch --status-fd 1 --verify "$SRC/$BIN.asc" "$stage/$BIN" 2>/dev/null) \ |
| 54 | && printf '%s\n' "$out" | grep -Eq "^\[GNUPG:\] VALIDSIG [0-9A-F]+ .* $key\$"; then # last field: primary key |
| 55 | echo "forgejo signature: good, key $key" |
| 56 | else |
| 57 | die "forgejo signature did not verify for key $key" |
| 58 | fi |
| 59 | |
| 60 | deb_got=$(sha256sum "$SRC/packages/$DEB" | cut -d' ' -f1) |
| 61 | deb_want=$(apt-cache show gocryptfs 2>/dev/null | awk -v f="${DEB}" '$1=="Filename:" && $2 ~ ("/" f "$") {m=1} m && $1=="SHA256:" && !d {print $2; d=1}') |
| 62 | [ -n "$deb_want" ] || die "apt-cache has no entry for $DEB; cannot check provenance" |
| 63 | [ "$deb_got" = "$deb_want" ] || die "gocryptfs deb sha256 $deb_got != Ubuntu index $deb_want" |
| 64 | echo "gocryptfs deb sha256: ok $deb_got (Ubuntu index)" |
| 65 | dpkg-deb -x "$SRC/packages/$DEB" "$stage/runtime" |
| 66 | [ -x "$stage/runtime/usr/bin/gocryptfs" ] || die "deb did not contain usr/bin/gocryptfs" |
| 67 | |
| 68 | echo "forgejo --version: $("$stage/$BIN" --version 2>&1 | head -n 1)" |
| 69 | echo "gocryptfs -version: $("$stage/runtime/usr/bin/gocryptfs" -version 2>&1 | head -n 1)" |
| 70 | command -v fusermount3 >/dev/null || die "fusermount3 missing; gocryptfs could not mount" |
| 71 | |
| 72 | if [ "$mode" = --dry-run ]; then |
| 73 | echo "dry-run: staged in $stage; live symlink untouched: $LINK -> $(readlink "$LINK")" |
| 74 | echo "--apply would: stage into $TARGET, then ln -sfn $TARGET $LINK" |
| 75 | exit 0 |
| 76 | fi |
| 77 | readlink "$LINK" >"$TARGET/previous-symlink-target" |
| 78 | ln -sfn "$TARGET" "$LINK" |
| 79 | echo "applied: $LINK -> $TARGET (previous target saved in $TARGET/previous-symlink-target)" |
| 80 | echo "next (root): sudo systemctl start atlas-forgejo.service; then: forgejo-backup --dry-run" |