feat: guard RPi4 image target and root staging

This commit is contained in:
juvenal.diaz 2026-10-24 08:57:56 -06:00
parent ff006691bf
commit de6443ef73
1 changed files with 14 additions and 1 deletions

View File

@ -36,7 +36,7 @@ plan_homelab() {
host_bootstrap_manage() {
local host_target="${1:-}"
local action="${2:-plan}"
local rpi_host rpi_user rpi_key rpi_os_image rpi_os_url
local rpi_host rpi_user rpi_key rpi_os_image rpi_os_url rpi_install_device
if [[ "${host_target}" != "rpi4" ]]; then
echo "Usage: ./jeannie host-bootstrap rpi4 [status|plan|apply --yes]" >&2
@ -51,6 +51,7 @@ host_bootstrap_manage() {
rpi_key="${LAB_RPI_SSH_KEY_PATH:-${LAB_RASPBERRY_SSH_KEY_PATH:-${HOME}/.ssh/id_ed25519}}"
rpi_os_image="${LAB_RPI4_OS_IMAGE_NAME:-Raspberry Pi OS Lite (64-bit)}"
rpi_os_url="${LAB_RPI4_OS_IMAGE_URL:-https://downloads.raspberrypi.com/raspios_lite_arm64_latest}"
rpi_install_device="${LAB_RPI4_INSTALL_DEVICE:-unset}"
case "${action}" in
status)
@ -72,6 +73,7 @@ target: ${rpi_user}@${rpi_host}
image: ${rpi_os_image}
image_url: ${rpi_os_url}
headless: true (no desktop packages)
install_device: ${rpi_install_device}
1. Provision the Raspberry Pi OS image through the configured network-boot or imaging provider.
2. Wait for SSH using ${rpi_key}.
@ -93,6 +95,17 @@ EOF
echo "LAB_RPI4_OS_PROVISIONER_COMMAND is required for RPi4 OS installation; refusing to guess a disk or boot target." >&2
return 2
fi
if [[ "${LAB_RPI4_INSTALL_DEVICE:-}" != "/dev/mmcblk0" ]]; then
echo "Set LAB_RPI4_INSTALL_DEVICE=/dev/mmcblk0 explicitly before applying the RPi4 image." >&2
return 2
fi
if ssh -i "${rpi_key}" -o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new \
"${rpi_user}@${rpi_host}" "test \"\$(findmnt -no SOURCE /)\" != \"${LAB_RPI4_INSTALL_DEVICE}\""; then
:
else
echo "Refusing to image ${LAB_RPI4_INSTALL_DEVICE}: it is still the RPi4 root filesystem. Boot the Pi from the Debian NFS staging root first." >&2
return 2
fi
echo "Running the configured RPi4 OS provisioner..."
export LAB_RPI4_OS_IMAGE_NAME="${rpi_os_image}" LAB_RPI4_OS_IMAGE_URL="${rpi_os_url}"
bash -lc "${LAB_RPI4_OS_PROVISIONER_COMMAND}"