ops: add doctrine anchor script and runbook

This commit is contained in:
vaultsovereign
2025-12-27 00:21:38 +00:00
parent 08b0a93c10
commit 59cf23e152
3 changed files with 142 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<USAGE
Usage:
anchor-doctrine-to-ledger.sh --ledger-dir <path> --receipt <path> [--tag <text>]
This script ingests an external receipt (typically produced by vm-cloud or other tool)
into vm-ledger, and records a local audit note.
Required:
--ledger-dir Path to vm-ledger directory (the repo root or ledger data dir expected by ledger-cli)
--receipt Path to a receipt JSON to ingest (verbatim)
Optional:
--tag Free-form tag to include in the local audit note
Example:
./80-automation/scripts/anchor-doctrine-to-ledger.sh \
--ledger-dir /Users/sovereign/vm/vm-ledger \
--receipt /Users/sovereign/vm/vm-cloud/outputs/receipts/<file>.json \
--tag "doctrine update"
USAGE
}
LEDGER_DIR=""
RECEIPT=""
TAG=""
while [[ $# -gt 0 ]]; do
case "$1" in
--ledger-dir) LEDGER_DIR="$2"; shift 2 ;;
--receipt) RECEIPT="$2"; shift 2 ;;
--tag) TAG="$2"; shift 2 ;;
-h|--help) usage; exit 0 ;;
*) echo "Unknown arg: $1"; usage; exit 2 ;;
esac
done
[[ -n "$LEDGER_DIR" ]] || { echo "Missing --ledger-dir"; usage; exit 2; }
[[ -n "$RECEIPT" ]] || { echo "Missing --receipt"; usage; exit 2; }
command -v cargo >/dev/null 2>&1 || { echo "cargo not found"; exit 2; }
ts="$(date -u +%Y%m%dT%H%M%SZ)"
out_dir="70-audits/reports/ledger"
mkdir -p "$out_dir"
note="$out_dir/${ts}-anchor-doctrine.txt"
echo "Anchoring receipt into ledger..." | tee "$note"
echo " ledger_dir: $LEDGER_DIR" | tee -a "$note"
echo " receipt: $RECEIPT" | tee -a "$note"
[[ -n "$TAG" ]] && echo " tag: $TAG" | tee -a "$note"
(
cd "$LEDGER_DIR"
cargo run -p ledger-cli -- ingest-external-receipt --dir "$LEDGER_DIR" --receipt "$RECEIPT"
) | tee -a "$note"
echo "OK: wrote audit note $note"