#!/usr/bin/env bash # Build a clean, single-commit tree of the current HEAD for a fresh public repository. Nothing is pushed. # # Usage: TESSERA_PRIVATE_TERMS=/path/to/terms.txt scripts/export-public.sh /path/to/empty-dir # scripts/export-public.sh --allow-unchecked /path/to/empty-dir # # TESSERA_PRIVATE_TERMS names a file, kept outside the repository, with one term per line (host names, # customer names, internal systems, personal names). The export is refused when any term occurs in the exported # tree. The variable must be set and the file must exist and contain at least one term; otherwise the script fails. # Pass --allow-unchecked only if you knowingly want to skip that check. # # Independently of the terms file, a given terms file also enables two pattern checks on the export: personal # e-mail addresses (anything that is not a documentation/placeholder address) and "@senkensha"-style hosts. set -euo pipefail allow_unchecked=0 out="" for arg in "$@"; do case "$arg" in --allow-unchecked) allow_unchecked=1 ;; -*) echo "unknown option: $arg" >&2; exit 2 ;; *) [ -z "$out" ] || { echo "only one target directory" >&2; exit 2; }; out="$arg" ;; esac done [ -n "$out" ] || { echo "usage: $0 [--allow-unchecked] " >&2; exit 2; } terms="${TESSERA_PRIVATE_TERMS:-}" if [ "$allow_unchecked" -eq 0 ]; then if [ -z "$terms" ]; then echo "refusing to export: TESSERA_PRIVATE_TERMS is not set (or pass --allow-unchecked to skip the private-terms check)" >&2 exit 1 fi if [ ! -f "$terms" ]; then echo "refusing to export: TESSERA_PRIVATE_TERMS=$terms is not a file" >&2 exit 1 fi if ! grep -q '[^[:space:]]' "$terms"; then echo "refusing to export: $terms contains no terms" >&2 exit 1 fi fi mkdir -p "$out" [ -z "$(ls -A "$out" 2>/dev/null)" ] || { echo "target must be empty" >&2; exit 1; } root="$(git rev-parse --show-toplevel)" git -C "$root" diff --quiet HEAD || { echo "commit or stash first" >&2; exit 1; } git -C "$root" archive HEAD | tar -x -C "$out" # Local tooling and agent state never belongs in a public tree, even if an old commit tracked it. for path in .serena .claude .cursor .idea .vscode graft floorplan .ignore web/AGENTS.md AGENTS.md CLAUDE.md \ web/blackhole-proto.html tasks; do rm -rf "${out:?}/$path" done if [ -n "$terms" ] && [ -f "$terms" ] && grep -q '[^[:space:]]' "$terms"; then fail=0 # 1. literal private terms (case-insensitive) if hits="$(grep -rIl -i -F -f "$terms" "$out" --exclude-dir=node_modules)"; [ -n "$hits" ]; then echo "private terms found in:" >&2 echo "$hits" >&2 fail=1 fi # 2. personal e-mail addresses: any address that is not a documentation or no-reply placeholder email='[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+' placeholder='@(example\.(com|org|net|invalid)|[A-Za-z0-9.-]*\.(example|invalid|test|localhost)|users\.noreply\.github\.com|noreply\.[A-Za-z0-9.-]+)$|:(noreply|no-reply)@' if hits="$(grep -rIoE "$email" "$out" --exclude-dir=node_modules --exclude=Cargo.lock --exclude=package-lock.json \ | grep -vE "$placeholder" || true)"; [ -n "$hits" ]; then echo "possible personal e-mail addresses (review, then remove or allow-list):" >&2 echo "$hits" | sort -u >&2 fail=1 fi # 3. "@senkensha"-style hosts (any host label containing the org name after an @ or in a URL) if hits="$(grep -rIiEl '@[A-Za-z0-9.-]*senkensha|https?://[A-Za-z0-9.-]*senkensha' "$out" --exclude-dir=node_modules || true)"; [ -n "$hits" ]; then echo "organisation-specific hosts found in:" >&2 echo "$hits" >&2 fail=1 fi [ "$fail" -eq 0 ] || exit 1 else echo "warning: --allow-unchecked given, so no check for private terms or personal e-mail addresses was made" >&2 fi cat <