Files
vm-cc/20-collectors/collect_constitution_hash.sh
2025-12-27 00:59:13 +00:00

28 lines
679 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
OUT_DIR="${1:?usage: collect_constitution_hash.sh <out_dir>}"
mkdir -p "$OUT_DIR"
LOCK_PATH="../vm-mcp/governance/constitution.lock"
hash_file() {
local file="$1"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$file" | awk '{print $1}'
else
shasum -a 256 "$file" | awk '{print $1}'
fi
}
if [[ -f "$LOCK_PATH" ]]; then
HASH="$(hash_file "$LOCK_PATH")"
cat > "$OUT_DIR/constitution_hash.json" <<JSON
{"collected": true, "path": "$LOCK_PATH", "sha256": "$HASH"}
JSON
else
cat > "$OUT_DIR/constitution_hash.json" <<'JSON'
{"collected": false, "reason": "constitution.lock not found at expected path"}
JSON
fi