#!/usr/bin/env bash # A folder a script deletes FROM must never be the home folder or anything # above it. On 4 Oct 2026 a prune pointed at a folder directly under $HOME # deleted most of a home folder; every script whose deletable root can be # moved by an environment variable or a flag asks this first. # # refuse_wide_root # # Exits 2 with a sentence when is empty, relative, `/`, has a `.` or `..` # in it, or is the home folder or a folder the home folder is inside — each as # written or as it resolves through symlinks. Sourced, never run. refuse_wide_root() { local what="$1" path="${2%/}" home="${HOME:-}" real="" home_real="" why="" home="${home%/}" if [ -z "$path" ]; then why="it is empty or /" else case "$path" in /*) ;; *) why="it is not an absolute path" ;; esac case "$path/" in */../* | */./*) why="it has a . or .. in it" ;; esac fi if [ -z "$why" ] && [ -n "$home" ]; then if [ -d "$path" ]; then real="$(cd "$path" 2>/dev/null && pwd -P)" || real=""; fi if [ -d "$home" ]; then home_real="$(cd "$home" 2>/dev/null && pwd -P)" || home_real=""; fi [ "$real" != "/" ] || why="it is /" local candidate inside for candidate in "$path" "$real"; do [ -n "$candidate" ] || continue for inside in "$home" "$home_real"; do [ -n "$inside" ] || continue case "$inside/" in "${candidate%/}"/*) why="it is the home folder or a folder the home folder is inside" ;; esac done done fi [ -z "$why" ] && return 0 echo "REFUSED: $what is '${2-}' — $why. This script deletes inside that folder, so it will not run there." >&2 exit 2 } # A missing protection helper is never permission to delete review evidence. evidence_kept() { local helper="$(dirname "${BASH_SOURCE[0]}")/evidence.py" status if python3 "$helper" keep "$1"; then return 0; else status=$?; fi [ "$status" -eq 1 ] && return 1 echo "kept $1 — EVIDENCE protection could not be inspected" >&2 return 0 }