#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SKILL_ROOT="$(dirname "$SCRIPT_DIR")" source "$SCRIPT_DIR/_common.sh" : "${BACKUP_SKILL_DIR:=}" : "${RUN_DIR:=}" main() { [[ -n "$BACKUP_SKILL_DIR" ]] || die "BACKUP_SKILL_DIR is required." local run_dir run_dir="$(resolve_run_dir "$BACKUP_SKILL_DIR" "$RUN_DIR")" [[ -d "$run_dir" ]] || die "RUN_DIR not found: $run_dir" local enc="$run_dir/archive.tar.gz.age" local manifest="$run_dir/manifest.json" local root="$run_dir/ROOT.txt" local proof="$run_dir/PROOF.json" [[ -f "$enc" ]] || die "Missing: $enc" [[ -f "$manifest" ]] || die "Missing: $manifest" [[ -f "$root" ]] || die "Missing: $root" [[ -f "$proof" ]] || die "Missing: $proof" local mb3 eb3 recomputed existing mb3="$(b3_file "$manifest")" eb3="$(b3_file "$enc")" recomputed="$(printf "%s\n%s\n" "$mb3" "$eb3" | (command -v b3sum >/dev/null 2>&1 && b3sum || blake3) | awk '{print $1}')" existing="$(tr -d ' \n\r\t' < "$root")" [[ "$recomputed" == "$existing" ]] || die "ROOT mismatch. existing=$existing recomputed=$recomputed" log_info "Validation OK: artifacts present and ROOT matches recomputation." log_info "Next: ./scripts/20_restore_plan.sh" } main "$@"