diff --git a/failover/sync-sd-backup.sh b/failover/sync-sd-backup.sh index f72a70e..dd2b7a7 100755 --- a/failover/sync-sd-backup.sh +++ b/failover/sync-sd-backup.sh @@ -19,9 +19,14 @@ # The bootloader in the SD's first sectors (idbloader/u-boot) is not touched. set -euo pipefail +# Backup settings come from the host config (see hosts/vanlink.conf.example). +# shellcheck disable=SC1090 +. "${VANLINK_CONF:-/etc/vanlink.conf}" +: "${SD_BACKUP_UUID:?set SD_BACKUP_UUID in /etc/vanlink.conf}" + [ "$(id -u)" -eq 0 ] || { echo "Run as root (sudo)." >&2; exit 1; } -SD_UUID=39118305-4927-47a4-acc7-ba022f37af22 +SD_UUID=$SD_BACKUP_UUID SD_ROOT_PART=/dev/disk/by-uuid/$SD_UUID MOUNT_POINT=/mnt/sd-backup-root FAILSAFE='boot-failesafe-rename-to:boot.scr' diff --git a/failover/sync-usb-backup.sh b/failover/sync-usb-backup.sh index 64396ca..4e4e090 100755 --- a/failover/sync-usb-backup.sh +++ b/failover/sync-usb-backup.sh @@ -11,15 +11,19 @@ # memory "sd-fallback-fstab-clobber" for what breaks if those leak across. set -euo pipefail +# Backup settings come from the host config (see hosts/vanlink.conf.example). +# shellcheck disable=SC1090 +. "${VANLINK_CONF:-/etc/vanlink.conf}" +: "${USB_BACKUP_ROOT_PART:?set USB_BACKUP_ROOT_PART in /etc/vanlink.conf}" +: "${USB_BACKUP_MOUNT:?set USB_BACKUP_MOUNT in /etc/vanlink.conf}" + [ "$(id -u)" -eq 0 ] || { echo "Run as root (sudo)." >&2; exit 1; } -USB_ROOT_PART=/dev/sda2 -MOUNT_POINT=/mnt/usb-backup-root -MOUNT_POINT=10.42.1.44:/media/andreas/writable-nvme +USB_ROOT_PART=$USB_BACKUP_ROOT_PART +MOUNT_POINT=$USB_BACKUP_MOUNT - -[[ "$MOUNT_POINT" == *":"* ]] -LOCAL_MOUNT=$? +# host:/path means an already-exported NFS target: nothing to mount locally. +if [[ "$MOUNT_POINT" == *":"* ]]; then LOCAL_MOUNT=0; else LOCAL_MOUNT=1; fi root_src=$(findmnt -no SOURCE /) if [ "$root_src" = "$USB_ROOT_PART" ]; then diff --git a/tests/check-templates.sh b/tests/check-templates.sh index f1a62fa..412db45 100755 --- a/tests/check-templates.sh +++ b/tests/check-templates.sh @@ -90,6 +90,24 @@ if awk ' END { exit bad } ' deploy.sh; then ok "flagged units are only touched inside their ENABLE_* guard"; else bad "flag gating"; fi +# 7. backup scripts take their settings from the host config and say what is missing +empty=$(mktemp); trap 'rm -f "$empty"' EXIT +for pair in "failover/sync-usb-backup.sh:USB_BACKUP_ROOT_PART" "failover/sync-sd-backup.sh:SD_BACKUP_UUID"; do + s=${pair%%:*}; v=${pair##*:} + if out=$(VANLINK_CONF="$empty" "./$s" 2>&1); then + bad "$s should fail when $v is not set" + elif echo "$out" | grep -q "$v"; then + ok "$s names missing $v" + else + bad "$s failed but did not mention $v"; echo "$out" | sed 's/^/ /' + fi +done +if grep -nE '/dev/sda2|10\.42\.[01]\.44|39118305-4927' failover/sync-*-backup.sh; then + bad "hardcoded host values remain in the backup scripts" +else + ok "no hardcoded devices/UUIDs/addresses in the backup scripts" +fi + # 8. ./deploy.sh --diff runs (no root) and lists rendered files if out=$(./deploy.sh --diff hosts/van.conf 2>&1) && echo "$out" | grep -qE '^(NEW|CHANGED) '; then ok "deploy.sh --diff hosts/van.conf"