sueta / deploy / publish-repo.sh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
# Builds the public git site for git-chat.ardegazu.ro: landing page + the repo
# as a dumb-HTTP-clonable bare mirror (plain static files — IPFS-friendly).
# After running, publish with: tunnel_set_offline tunnel=git-chat.ardegazu.ro path=deploy/.site
set -euo pipefail
cd "$(dirname "$0")/.."

OUT=deploy/.site
rm -rf "$OUT"
mkdir -p "$OUT"

cp site/index.html "$OUT/index.html"
python3 deploy/gen-browse.py "$OUT"

# --no-local: a plain path clone hardlinks the whole objects dir, which can
# drag along unreachable/rewritten history — transport clone copies only
# what's reachable from refs
git clone --no-local --bare --quiet . "$OUT/sueta.git"

# Explode packs into loose objects: the IPFS gateway answers missing paths
# with a 200 fallback page, which makes git's loose-object probes error
# noisily before the pack fallback. All-loose means every requested path
# exists, so dumb-HTTP clones stay clean.
(
  cd "$OUT/sueta.git"
  for p in objects/pack/pack-*.pack; do
    [ -e "$p" ] || continue
    tmp=$(mktemp)
    mv "$p" "$tmp"
    rm -f "${p%.pack}".*
    git unpack-objects -q < "$tmp"
    rm -f "$tmp"
  done
  git update-server-info
)
# strip local-only noise from the published mirror
rm -rf "$OUT/sueta.git/hooks" "$OUT/sueta.git/config" 2>/dev/null || true

# ---- anonymity gate: refuse to build a mirror that leaks identity ----------
AUTHORS=$(git -C "$OUT/sueta.git" log --all --format='%an <%ae>%n%cn <%ce>' | sort -u)
if [ "$AUTHORS" != "sueta <sueta@noreply.local>" ]; then
  echo "ABORT: non-anonymous commit identity in mirror:" >&2
  echo "$AUTHORS" >&2
  exit 1
fi
if git -C "$OUT/sueta.git" ls-tree -r --name-only HEAD | grep -q '\.site'; then
  echo "ABORT: nested site build committed into the repo (deploy/.site leak)" >&2
  exit 1
fi
# pattern assembled from pieces so this script never matches itself
IDPAT="$(printf 'koko%s|rober%s@' s t)"
LEAK=$(cd "$OUT/sueta.git" && find objects -type f | while read -r f; do
  python3 -c "import zlib,sys;sys.stdout.buffer.write(zlib.decompress(open('$f','rb').read()))" 2>/dev/null
done | grep -aicE "$IDPAT" || true)
if [ "${LEAK:-0}" != "0" ]; then
  echo "ABORT: identity strings found inside $LEAK mirror object(s)" >&2
  exit 1
fi
echo "anonymity gate: OK (single anonymous author, no identity bytes, no nested site)"
# -----------------------------------------------------------------------------

echo "site built at $OUT ($(du -sh "$OUT" | cut -f1)) — publish via tunnel_set_offline"