testsAndMisc/linux_configuration/hosts/guard/pacman-hooks/pacman-pre-unlock-hosts.sh
Krzysztof kuhy Rudnicki f84135f6d7 linux_configuration: WIP digital_wellbeing + pacman hosts-guard updates
Pre-existing local changes from a prior session, committed together for
cleanup. Touches:

- hosts/guard/: pacman pre-unlock / post-relock hook tweaks and the
  shared hosts-guard-common.sh helper.
- scripts/digital_wellbeing/: block_compulsive_opening, music_parallelism,
  setup_midnight_shutdown, setup_pc_startup_monitor refinements.
- scripts/digital_wellbeing/pacman/pacman_wrapper.sh: substantial rewrite.
- scripts/lib/common.sh: shared helpers expanded.
- tests/test_hosts_guard_pacman_integration.sh: new integration test.
2026-05-06 21:41:07 +02:00

32 lines
811 B
Bash
Executable File

#!/usr/bin/env bash
# pacman-pre-unlock-hosts.sh - Temporarily unlock guarded config files before pacman
# Unlocks: /etc/hosts, /etc/nsswitch.conf, /etc/systemd/resolved.conf
set -euo pipefail
# Source shared functions
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=hosts-guard-common.sh
source "$SCRIPT_DIR/hosts-guard-common.sh"
require_root
log_hook "pre" "unlocking(start)"
# Remove protective attributes from all guarded files
remove_all_guard_attrs
# Stop guard services (hosts, nsswitch, resolved watchers)
stop_units_if_present
# Collapse any existing mount layers
collapse_mounts
# Ensure writable by remounting if still read-only
if is_ro_mount; then
mount -o remount,rw "$TARGET" >/dev/null 2>&1 || collapse_mounts
fi
log_hook "pre" "unlocking(done)"
exit 0