#!/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 # # TESSERA_PRIVATE_TERMS names a file, kept outside the repository, with one term per line (host names, # customer names, internal systems). If any of them occurs in the exported tree the export is refused. set -euo pipefail out="${1:?target directory}" [ -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" if [ -n "${TESSERA_PRIVATE_TERMS:-}" ]; then if grep -rIl -i -F -f "$TESSERA_PRIVATE_TERMS" "$out" --exclude-dir=node_modules >/dev/null; then echo "private terms found in:" >&2 grep -rIl -i -F -f "$TESSERA_PRIVATE_TERMS" "$out" --exclude-dir=node_modules >&2 exit 1 fi else echo "note: TESSERA_PRIVATE_TERMS is not set, so no check for private terms was made" >&2 fi echo "clean tree at $out; review it, then: git init && git add -A && git commit"