#!/usr/bin/env bash set -euo pipefail # === METADATA === SCRIPT_NAME="$(basename "$0")" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SKILL_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" # === CONFIGURATION === : "${OUTPUT_DIR:=$SKILL_ROOT/outputs}" # === FUNCTIONS === log_info() { echo "[INFO] $(date -Iseconds) $*"; } log_warn() { echo "[WARN] $(date -Iseconds) $*" >&2; } log_error() { echo "[ERROR] $(date -Iseconds) $*" >&2; } die() { log_error "$@"; exit 1; } main() { if [[ ! -d "$OUTPUT_DIR" ]]; then log_info "Output directory does not exist. Nothing to purge." exit 0 fi local run_count=0 if [[ -d "$OUTPUT_DIR/runs" ]]; then run_count=$(find "$OUTPUT_DIR/runs" -mindepth 1 -maxdepth 1 -type d | wc -l | tr -d ' ') fi log_warn "This will PERMANENTLY DELETE all backup outputs:" log_warn " Directory: $OUTPUT_DIR" log_warn " Backup runs: $run_count" log_warn "" log_warn "This action cannot be undone!" echo "" echo "Type 'PURGE ALL' to confirm:" read -r confirm [[ "$confirm" == "PURGE ALL" ]] || die "Aborted." # Clean up any restore drill temp directories if [[ -d "$OUTPUT_DIR/runs" ]]; then for run_dir in "$OUTPUT_DIR/runs"/*; do if [[ -f "$run_dir/last_restore_dir.txt" ]]; then local restore_dir restore_dir="$(cat "$run_dir/last_restore_dir.txt")" if [[ -d "$restore_dir" ]]; then log_info "Removing restore temp: $restore_dir" rm -rf "$restore_dir" fi fi done fi log_info "Purging outputs directory..." rm -rf "$OUTPUT_DIR"/* log_info "Purge complete." } [[ "${BASH_SOURCE[0]}" == "$0" ]] && main "$@"