#!/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"