utils/guard-lib/pacman-hooks/guard-lib-relock-all.sh
Krzysztof kuhy Rudnicki c99cb8373e feat: initial guard-lib - shared tamper-resistance primitives
Extracts the chattr+bind-mount+systemd-watcher file-locking pattern (and a
new pacman PreTransaction package-block primitive) out of screen-locker and
steam-backlog-enforcer into a standalone, config-driven library so both
projects (and steam-backlog-enforcer's new block-gaming feature) can share
one implementation instead of maintaining parallel copies.

- guardctl: CLI entry point (file-guard, package-block subcommands)
- lib/file_guard.sh: chattr +i / bind-mount / systemd-path-watcher / pacman
  hook enforcement for a single target file, keyed by /etc/guard-lib/targets
  config; includes `sync` (adopt current content as canonical - for a
  caller's own legitimate edit) distinct from `pacman-relock` (revert drift)
- lib/package_block.sh: time-locked pacman PreTransaction hook that refuses
  to (re)install a given package while a lock file's `until` timestamp is in
  the future; supports --bind-mount to compose with file-guard on the same
  lock file
- pacman-hooks/: the installed hook scripts + .hook definitions
- systemd/: guard-file@.path/.service watcher units, guard-bind-mount@.service

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFNiYQQgSLAkiBXswyimPq
2026-07-04 11:47:59 +02:00

21 lines
769 B
Bash
Executable File

#!/bin/bash
# PostTransaction hook script: re-enforce every registered file-guard
# instance (restores drift if pacman legitimately rewrote the file, then
# re-locks it). Same fail-open discipline as guard-lib-unlock-all.sh - a
# single broken instance logs a warning and the loop continues.
set -uo pipefail
TARGETS_DIR="${GUARD_LIB_TARGETS_DIR:-/etc/guard-lib/targets}"
GUARDCTL="${GUARD_LIB_BIN:-/usr/local/bin/guardctl}"
if [[ -d "$TARGETS_DIR" ]]; then
for conf in "$TARGETS_DIR"/*.conf; do
[[ -e "$conf" ]] || continue
name="$(basename "$conf" .conf)"
"$GUARDCTL" file-guard pacman-relock "$name" 2>/dev/null || \
echo "guard-lib: WARNING failed to re-lock '$name' after transaction (continuing)" >&2
done
fi
exit 0