testsAndMisc/meta/scripts/report_live_state.sh
Krzysztof kuhy Rudnicki 3cd42a4451 Restructure step 0: live-state inventory + depth gate dry run
Two scripts and a baseline record, ahead of the archive/extract/flatten
campaign. Nothing moves in this commit.

report_live_state.sh enumerates everything on this machine that names an
absolute path inside the repo -- 6 systemd units, 2 /etc/guard-lib plugin
targets and 19 symlinks. Moving a subtree silently breaks these, so each
later step repoints its own references and re-runs this with --check.

check_directory_depth.sh is the 2-directory cap, modelled on
check_file_length.sh. It is deliberately NOT wired into pre-commit yet:
the tree has 556 violations, so enforcing it now would block every
unrelated commit -- the same reason file-length-cap landed after its
campaign rather than before.

Run as a dry run it sizes the work: 349 of those 556 disappear with the
planned removals, leaving 207 to flatten, ~130 of them under
scripts/single_use.

Exemptions are prefix-based (third_party/, docs/superpowers/,
.github/skills/) plus the lib/ and tests/ path segments, matched as whole
segments so libvirt/ and lib.sh are not caught. Capping lib/ and tests/
would put this gate in conflict with the 250-line cap and the
shell-coverage ratchet, which require exactly that layout.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 16:59:54 +02:00

120 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# ============================================================================
# Report every place on this machine that points into this repo.
#
# The restructure moves whole subtrees out of testsAndMisc. Anything that
# names a path inside the repo - a systemd unit, an /etc config, a symlink on
# PATH - keeps pointing at the old location and breaks silently once the
# target moves. This script is the checklist: run it before a move to record
# what must be repointed, and after a move to prove nothing was missed.
#
# report_live_state.sh # human-readable report
# report_live_state.sh --check # exit 1 if anything still points here
#
# --check is the post-move gate. A clean run means no live reference remains.
# ============================================================================
set -euo pipefail
SCRIPT_NAME="$(basename "$0")"
readonly SCRIPT_NAME
readonly REPO="${REPO:-$HOME/testsAndMisc}"
CHECK_ONLY=0
usage() {
echo "Usage: $SCRIPT_NAME [--check]"
echo "Options:"
echo " --check Exit 1 if any live reference into the repo remains"
echo " -h, --help Show this help"
exit 0
}
# Units whose ExecStart/WorkingDirectory/Environment names a repo path.
# Root units need no privilege to read; user units live under $HOME.
report_systemd() {
echo "## systemd units"
local found=0 unit
while IFS= read -r unit; do
[[ -n "$unit" ]] || continue
found=1
printf ' %s\n' "$unit"
grep -n "$REPO\|%h/testsAndMisc" "$unit" | sed 's/^/ /'
done < <(grep -rl "$REPO\|%h/testsAndMisc" \
/etc/systemd/system "$HOME/.config/systemd/user" 2>/dev/null | sort)
((found)) || echo " (none)"
return "$found"
}
# Non-unit config under /etc that hardcodes a repo path (guard-lib targets,
# sudoers drop-ins, pacman hooks).
report_etc() {
echo "## /etc references"
local found=0 path
while IFS= read -r path; do
[[ -n "$path" ]] || continue
case "$path" in */systemd/*) continue ;; esac
found=1
printf ' %s\n' "$path"
grep -n "$REPO" "$path" 2>/dev/null | sed 's/^/ /'
done < <(grep -rl "$REPO" /etc 2>/dev/null | sort)
((found)) || echo " (none)"
return "$found"
}
# Symlinks anywhere in $HOME resolving into the repo: i3blocks, ~/.local/bin,
# oh-my-zsh custom. Depth 4 covers every known location without walking the
# whole home directory.
report_symlinks() {
echo "## symlinks into the repo"
local found=0 link target
while IFS= read -r link; do
[[ -n "$link" ]] || continue
found=1
target="$(readlink "$link")"
printf ' %s -> %s\n' "$link" "$target"
done < <(find "$HOME" -maxdepth 4 -type l -lname "*testsAndMisc*" \
-not -path "$REPO/*" 2>/dev/null | sort)
((found)) || echo " (none)"
return "$found"
}
main() {
local any=0
report_systemd || any=1
echo
report_etc || any=1
echo
report_symlinks || any=1
if ((CHECK_ONLY)); then
if ((any)); then
echo
echo "$SCRIPT_NAME: live references into $REPO remain (see above)" >&2
return 1
fi
echo
echo "$SCRIPT_NAME: no live reference points into $REPO"
fi
return 0
}
while [[ $# -gt 0 ]]; do
case "$1" in
--check)
CHECK_ONLY=1
shift
;;
-h | --help)
usage
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done
main