#!/usr/bin/env bash # Flash the Pi 4 image to an SD card / USB SSD. # Usage: sudo ./flash-rpi.sh /dev/sdX [image[.gz|.zst]] (check `lsblk` first!) set -euo pipefail cd "$(dirname "$0")" DEV="${1:?usage: sudo ./flash-rpi.sh /dev/sdX}" IMG="${2:-guix-rpi4-claude.img}" case "$DEV" in /dev/nvme[0-9]*n1|/dev/mmcblk[0-9]|/dev/sd[a-z]) ;; *) echo "refusing suspicious device $DEV (partition? use the whole disk)" >&2; exit 1 ;; esac [ -e "$DEV" ] || { echo "no such device $DEV" >&2; exit 1; } read -rp "About to OVERWRITE $DEV with $IMG. Type the device name to confirm: " ok [ "$ok" = "$DEV" ] || { echo "aborted"; exit 1; } case "$IMG" in *.gz) gzip -dc "$IMG" | sudo dd of="$DEV" bs=4M status=progress conv=fsync ;; *.zst) zstd -dc --long=27 "$IMG" | sudo dd of="$DEV" bs=4M status=progress conv=fsync ;; *) sudo dd if="$IMG" of="$DEV" bs=4M status=progress conv=fsync ;; esac sudo sync echo "done"