#!/usr/bin/env bash # Delete the generated POC runtime state at /home/jwoltje/.mosaic-dev, # but ONLY when every safety check passes: # 1. The resolved path is exactly /home/jwoltje/.mosaic-dev. # 2. The path is not a symbolic link. # 3. The directory contains the .mosaic-poc-root ownership marker # created by this project. # Any failed check aborts with nothing deleted. set -euo pipefail cd "$(dirname "$0")/.." # shellcheck source=common.sh source scripts/common.sh # Reset operates on the CONFIGURED data root. Configuration itself is # never a reset target; a missing/invalid configuration aborts here. load_config TARGET="$MOSAIC_DATA_ROOT" MARKER="$POC_ROOT_MARKER" fail() { echo "reset: refusing to delete: $*" >&2 exit 1 } # Nothing to do when the directory does not exist. if [ ! -e "$TARGET" ]; then echo "reset: $TARGET does not exist; nothing to remove" exit 0 fi # Check 2 (before resolution): the path itself must not be a symlink. if [ -L "$TARGET" ]; then fail "$TARGET is a symbolic link" fi # Check 1: resolved path must be exactly the POC runtime directory. RESOLVED="$(realpath "$TARGET")" if [ "$RESOLVED" != "$TARGET" ]; then fail "resolved path $RESOLVED is not $TARGET" fi # Check 3: ownership marker created by this project must be present. if [ ! -f "$TARGET/$MARKER" ]; then fail "missing $MARKER ownership marker in $TARGET" fi rm -rf -- "$TARGET" echo "reset: removed $TARGET"