#!/usr/bin/env bash
set -euo pipefail
ROOT="${1:-/srv/project-frankenstein}"
STAMP=$(date -u +%Y%m%dT%H%M%SZ)
OUT="$ROOT/recovery/git-bundles/$STAMP"
mkdir -p "$OUT"
echo 'WARNING: bundles on the same physical disk are recovery aids, not backups.'
for repo in "$ROOT"/repos/*.git; do
  [[ -d "$repo" ]] || continue
  name=$(basename "$repo" .git)
  git --git-dir="$repo" bundle create "$OUT/$name.bundle" --all
  sha256sum "$OUT/$name.bundle" > "$OUT/$name.bundle.sha256"
done
find "$OUT" -maxdepth 1 -type f -printf '%f %s bytes\n'
