mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-06 17:03:10 +02:00
- Move fresh-install/ → scripts/single_use/fresh-install/ - Move hosts/ → scripts/periodic_background/hosts/ - Move i3-configuration/ → scripts/periodic_background/i3-configuration/ - Delete linux_configuration/LaTeX/, nix-poc/, report/ (dead dirs) - Move repo-root scripts/ → meta/scripts/ - Update root .pre-commit-config.yaml: scripts/ → meta/scripts/ (9 entries) - Update run.sh ARTIFACT_INIT_SCRIPT to meta/scripts/ - Update fresh-install/main.sh: hosts/install.sh + i3-configuration/install.sh paths - Update check_python_location.sh: add meta/scripts/ to exception list - Fix midnight flakiness in test_recent_workout_returns_true: use timezone-aware local noon instead of now-1h to avoid SQL date() boundary issues
33 lines
965 B
Bash
Executable File
33 lines
965 B
Bash
Executable File
#!/bin/bash
|
||
# Template guard script to enforce canonical /etc/hosts
|
||
# This will be installed into /usr/local/sbin/enforce-hosts.sh by a setup script.
|
||
|
||
set -euo pipefail
|
||
|
||
CANONICAL_SOURCE="/usr/local/share/locked-hosts"
|
||
TARGET="/etc/hosts"
|
||
LOG_FILE="/var/log/hosts-guard.log"
|
||
|
||
log() {
|
||
printf '%s - %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*" | tee -a "$LOG_FILE" >&2
|
||
}
|
||
|
||
if [[ ! -f $CANONICAL_SOURCE ]]; then
|
||
log "Canonical hosts not found at $CANONICAL_SOURCE; aborting enforcement"
|
||
exit 0
|
||
fi
|
||
|
||
if ! cmp -s "$CANONICAL_SOURCE" "$TARGET"; then
|
||
log "Difference detected – restoring $TARGET from canonical copy"
|
||
cp "$CANONICAL_SOURCE" "$TARGET"
|
||
chmod 644 "$TARGET"
|
||
else
|
||
log "No drift detected (contents identical)"
|
||
fi
|
||
|
||
# Re-apply protective attributes: immutable first, then read-only bind mount handled by separate unit
|
||
chattr -i -a "$TARGET" 2> /dev/null || true
|
||
chattr +i "$TARGET" || log "Failed to set immutable attribute"
|
||
|
||
log "Enforcement complete"
|