interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / infra / spark / forgejo / forgejo-runtime-restore.sh

80 lines · 4776 bytes Raw Blame History
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).
24set -euo pipefail
25umask 022
26SRC=${SRC:-/home/atlas/atlas-forgejo-setup-20260904}
27TARGET=${TARGET:-$HOME/.local/opt/atlas-forgejo-runtime-20260904}
28LINK=${LINK:-$HOME/atlas-forgejo-setup-20260904}
29BIN=forgejo-16.0.3-linux-arm64
30DEB=gocryptfs_2.4.0-1ubuntu0.24.04.3_arm64.deb
31
32mode=${1:-}
33case $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 ;;
37esac
38die() { 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"
41mkdir -p "$stage/runtime"
42[ -z "$(ls -A "$stage/runtime")" ] || die "$stage/runtime is not empty; refusing to overwrite"
43
44want=$(sed -n 's/.*"sha256": *"\([0-9a-f]*\)".*/\1/p' "$SRC/binary-proof.json")
45key=$(sed -n 's/.*"signingKey": *"\([0-9A-F]*\)".*/\1/p' "$SRC/binary-proof.json")
46install -m 755 "$SRC/$BIN" "$stage/$BIN"
47got=$(sha256sum "$stage/$BIN" | cut -d' ' -f1)
48[ "$got" = "$want" ] || die "forgejo sha256 $got != binary-proof.json $want"
49echo "forgejo sha256: ok $got (binary-proof.json)"
50
51gh=$(mktemp -d); trap 'rm -rf "$gh"' EXIT
52cp "$SRC/gnupg/pubring.kbx" "$gh/" # public keyring only, never private-keys-v1.d
53if 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"
56else
57 die "forgejo signature did not verify for key $key"
58fi
59
60deb_got=$(sha256sum "$SRC/packages/$DEB" | cut -d' ' -f1)
61deb_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"
64echo "gocryptfs deb sha256: ok $deb_got (Ubuntu index)"
65dpkg-deb -x "$SRC/packages/$DEB" "$stage/runtime"
66[ -x "$stage/runtime/usr/bin/gocryptfs" ] || die "deb did not contain usr/bin/gocryptfs"
67
68echo "forgejo --version: $("$stage/$BIN" --version 2>&1 | head -n 1)"
69echo "gocryptfs -version: $("$stage/runtime/usr/bin/gocryptfs" -version 2>&1 | head -n 1)"
70command -v fusermount3 >/dev/null || die "fusermount3 missing; gocryptfs could not mount"
71
72if [ "$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
76fi
77readlink "$LINK" >"$TARGET/previous-symlink-target"
78ln -sfn "$TARGET" "$LINK"
79echo "applied: $LINK -> $TARGET (previous target saved in $TARGET/previous-symlink-target)"
80echo "next (root): sudo systemctl start atlas-forgejo.service; then: forgejo-backup --dry-run"