#!/usr/bin/env bash
# Builds this repo's public source mirror: landing page + the repo as a
# dumb-HTTP-clonable bare mirror (plain static files — IPFS-friendly).
# Published as part of the git.ardegazu.ro ecosystem root by
# the workspace assembler (git/assemble.sh), which serves it at
# https://git.ardegazu.ro/game6/ (page) and https://git.ardegazu.ro/game6.git (clone).
set -euo pipefail
cd "$(dirname "$0")/.."
APP=game6 # path under git.ardegazu.ro
IDENT=odeon # anonymous commit identity
OUT=deploy/.site
rm -rf "$OUT"
mkdir -p "$OUT"
cp site/index.html "$OUT/index.html"
# this ecosystem's assembler rsyncs only — each repo generates its own
# in-browser source browser (git.ardegazu.ro/<APP>/browse/)
python3 deploy/gen-browse.py --repo . --app "$APP" --out "$OUT/browse" \
--clone-url "https://git.ardegazu.ro/$APP.git"
# --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/$APP.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/$APP.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/$APP.git/hooks" "$OUT/$APP.git/config" 2>/dev/null || true
# ---- anonymity gate: refuse to build a mirror that leaks identity ----------
AUTHORS=$(git -C "$OUT/$APP.git" log --all --format='%an <%ae>%n%cn <%ce>' | sort -u)
if [ "$AUTHORS" != "$IDENT <$IDENT@noreply.local>" ]; then
echo "ABORT: non-anonymous commit identity in mirror:" >&2
echo "$AUTHORS" >&2
exit 1
fi
if git -C "$OUT/$APP.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@|@mu%s' s t k)"
LEAK=$(cd "$OUT/$APP.git" && find objects -type f | while read -r f; do
# filename via argv, never interpolated into source (injection-proof pattern)
python3 -c "import zlib,sys;sys.stdout.buffer.write(zlib.decompress(open(sys.argv[1],'rb').read()))" "$f" 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 "mirror built at $OUT ($(du -sh "$OUT" | cut -f1)) — publish via ardegazu-git/assemble.sh $APP"