interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / infra / bazinga / sync.sh
| 1 | #!/usr/bin/env bash |
| 2 | # bazinga-git/sync.sh [name...]: fill the public read-only clone copies behind |
| 3 | # git clone https://interplane.io/drakestapleton/<name>.git |
| 4 | # from the canonical plain-git repositories spark:~/git/<name>.git (branches and tags only). |
| 5 | # Served by nginx as plain files (git "dumb" HTTP) from /var/www/interplane-git/<name>.git. |
| 6 | # A name is published only when the owner store catalog lists it as public and neither the name |
| 7 | # nor a ref contains pearl/crypto/private (the rule of the old /code page). Run with no names |
| 8 | # for all; each ~/git/<name>.git/hooks/post-update runs it for its own name after every push. |
| 9 | # Written 2026-11-15 (mac-cc/Recovery, Drake: "put git back in place over interplane.io"). |
| 10 | set -u |
| 11 | unset GIT_DIR GIT_WORK_TREE GIT_QUARANTINE_PATH GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES |
| 12 | SRC=${BAZINGA_SRC:-$HOME/git} |
| 13 | DST=${BAZINGA_DST:-/var/www/interplane-git} |
| 14 | CAT=${BAZINGA_CATALOG:-$HOME/interplane-store-owner/catalog.tsv} |
| 15 | BAD='pearl|crypto|private' |
| 16 | [ -r "$CAT" ] || { echo "FAIL no catalog $CAT"; exit 2; } |
| 17 | if [ $# -gt 0 ]; then names=("$@"); else mapfile -t names < <(ls "$SRC" | sed -n 's/\.git$//p'); fi |
| 18 | rc=0 |
| 19 | for n in "${names[@]}"; do |
| 20 | s=$SRC/$n.git; d=$DST/$n.git |
| 21 | case $n in ''|.*|*/*) echo "SKIP $n bad name"; continue ;; esac |
| 22 | [ -d "$s" ] || { echo "SKIP $n no source"; continue; } |
| 23 | if ! awk -F'\t' -v n="$n" '$1==n && $5=="public" {f=1} END {exit !f}' "$CAT" || echo "$n" | grep -qiE "$BAD"; then |
| 24 | [ -d "$d" ] && rm -rf "$d" |
| 25 | echo "SKIP $n not public"; continue |
| 26 | fi |
| 27 | if [ ! -d "$d" ]; then |
| 28 | git init -q --bare "$d" || { echo "FAIL $n init"; rc=1; continue; } |
| 29 | fi |
| 30 | # Branch downloads represent the stored Git blobs, including export-ignored paths. |
| 31 | attrs='* -export-ignore -export-subst -text -crlf !eol !working-tree-encoding -ident -filter' |
| 32 | if ! grep -Fxq -- "$attrs" "$d/info/attributes" 2>/dev/null; then |
| 33 | printf '\n%s\n' "$attrs" >> "$d/info/attributes" || { rc=1; continue; } |
| 34 | fi |
| 35 | head=$(git --git-dir "$s" symbolic-ref -q HEAD || echo refs/heads/main) |
| 36 | git --git-dir "$d" symbolic-ref HEAD "$head" |
| 37 | specs=() |
| 38 | while read -r r; do |
| 39 | echo "$r" | grep -qiE "$BAD" && continue |
| 40 | specs+=("+$r:$r") |
| 41 | done < <(git --git-dir "$s" for-each-ref --format='%(refname)' refs/heads refs/tags) |
| 42 | [ ${#specs[@]} -gt 0 ] || { echo "SKIP $n no refs"; continue; } |
| 43 | git --git-dir "$s" push -q "$d" "${specs[@]}" || { echo "FAIL $n push"; rc=1; continue; } |
| 44 | # refs gone at the source go here too |
| 45 | git --git-dir "$d" for-each-ref --format='%(refname)' refs/heads refs/tags | while read -r r; do |
| 46 | git --git-dir "$s" show-ref --verify -q "$r" || git --git-dir "$d" update-ref -d "$r" |
| 47 | done |
| 48 | [ "$(find "$d/objects" -maxdepth 1 -type d -name '[0-9a-f][0-9a-f]' | wc -l)" -gt 64 ] && git --git-dir "$d" gc -q 2>/dev/null |
| 49 | git --git-dir "$d" update-server-info |
| 50 | chmod -R a+rX "$d" |
| 51 | echo "OK $n $(git --git-dir "$d" rev-parse --short "$head" 2>/dev/null)" |
| 52 | done |
| 53 | exit $rc |