← back to Sound Agentabrams

sync.sh

27 lines

#!/bin/bash
# Reconcile standalone source builds -> this topic hub (sounds/<id>/).
# Mapping lives in sources.tsv: "<hub-id>\t<abs-source-project-path>".
# Usage: ./sync.sh [--commit]
set -euo pipefail
HUB="$(cd "$(dirname "$0")" && pwd)"
MAP="$HUB/sources.tsv"
[ -f "$MAP" ] || { echo "no sources.tsv"; exit 0; }
changed=0
while IFS=$'\t' read -r id src; do
  [ -z "${id:-}" ] && continue
  case "$id" in \#*) continue;; esac
  src="${src/#\~/$HOME}"
  dest="$HUB/sounds/$id"
  if [ ! -d "$src" ]; then echo "! source missing for $id: $src"; continue; fi
  mkdir -p "$dest"
  if ! cmp -s "$src/index.html" "$dest/index.html" 2>/dev/null; then
    cp "$src/index.html" "$dest/index.html"; echo "synced index.html -> sounds/$id/"; changed=1
  fi
  for aa in "$src"/*.aa; do [ -e "$aa" ] || continue; cp "$aa" "$dest/"; done
done < "$MAP"
[ "$changed" = 1 ] && echo "sync: updates applied" || echo "sync: all in sync"
if [ "${1:-}" = "--commit" ] && [ -n "$(git -C "$HUB" status --porcelain)" ]; then
  git -C "$HUB" add -A
  git -C "$HUB" -c user.email="steve@designerwallcoverings.com" -c user.name="Steve" commit -q -m "sync builds from source" && echo "committed hub"
fi