2025-10-31 17:50:11 +01:00
|
|
|
#!/usr/bin/env bash
|
2025-12-11 18:42:03 +01:00
|
|
|
# pacman-pre-unlock-hosts.sh - Temporarily unlock /etc/hosts before pacman
|
2025-11-06 20:24:19 +01:00
|
|
|
set -euo pipefail
|
|
|
|
|
|
2025-12-11 18:32:15 +01:00
|
|
|
# Source shared functions
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
|
# shellcheck source=hosts-guard-common.sh
|
|
|
|
|
source "$SCRIPT_DIR/hosts-guard-common.sh"
|
2025-10-31 17:50:11 +01:00
|
|
|
|
2025-12-11 18:32:15 +01:00
|
|
|
# Remove protective attributes
|
|
|
|
|
remove_host_attrs
|
2025-10-31 17:50:11 +01:00
|
|
|
|
2025-12-11 18:32:15 +01:00
|
|
|
# Stop guard services
|
2025-10-31 17:50:11 +01:00
|
|
|
stop_units_if_present
|
|
|
|
|
|
2025-12-11 18:32:15 +01:00
|
|
|
log_hook "pre" "unlocking(start)"
|
2025-10-31 17:50:11 +01:00
|
|
|
|
2025-12-11 18:32:15 +01:00
|
|
|
# Collapse any existing mount layers
|
|
|
|
|
collapse_mounts
|
2025-10-31 17:50:11 +01:00
|
|
|
|
2025-12-11 18:32:15 +01:00
|
|
|
# Ensure writable by remounting if still read-only
|
2025-10-31 17:50:11 +01:00
|
|
|
if is_ro_mount; then
|
2026-01-07 22:52:20 +01:00
|
|
|
mount -o remount,rw "$TARGET" > /dev/null 2>&1 || collapse_mounts
|
2025-10-31 17:50:11 +01:00
|
|
|
fi
|
|
|
|
|
|
2025-12-11 18:32:15 +01:00
|
|
|
log_hook "pre" "unlocking(done)"
|
2025-10-31 17:50:11 +01:00
|
|
|
|
|
|
|
|
exit 0
|