Jim Ostrowski | c58989a | 2022-01-29 16:12:08 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | # Disk image to use for creating SD card |
| 6 | # NOTE: You MUST run modify_rootfs.sh on this image BEFORE running make_sd.sh |
| 7 | ORIG_IMAGE="2021-10-30-raspios-bullseye-armhf-lite.img" |
| 8 | IMAGE=`echo ${ORIG_IMAGE} | sed s/.img/-frc-mods.img/` |
| 9 | DEVICE="/dev/sda" |
| 10 | |
| 11 | if mount | grep "${DEVICE}" >/dev/null ; |
| 12 | then |
| 13 | echo "Overwriting a mounted partition, is ${DEVICE} the sd card?" |
| 14 | exit 1 |
| 15 | fi |
| 16 | |
| 17 | sudo dd if=${IMAGE} of=${DEVICE} bs=1M status=progress |
| 18 | |
| 19 | PARTITION="${IMAGE}.partition" |
| 20 | |
| 21 | mkdir -p "${PARTITION}" |
| 22 | sudo mount "${DEVICE}2" "${PARTITION}" |
| 23 | |
| 24 | function target() { |
| 25 | HOME=/root/ USER=root sudo proot -0 -q qemu-arm-static -w / -r "${PARTITION}" "$@" |
| 26 | } |
| 27 | |
| 28 | if [ "${1}" == "" ]; then |
| 29 | echo "No hostname specified, so skipping setting it." |
| 30 | echo "You do this manually on the pi by running /root/bin/change_hostname.sh PI_NAME" |
| 31 | else |
| 32 | target /root/bin/change_hostname.sh "${1}" |
| 33 | fi |
| 34 | |
| 35 | echo "Starting a shell for any manual configuration" |
| 36 | target /bin/bash --rcfile /root/.bashrc |
| 37 | |
| 38 | # Put a timestamp on when this card got created and by whom |
| 39 | TIMESTAMP_FILE="${PARTITION}/home/pi/.DiskFlashedDate.txt" |
| 40 | date > "${TIMESTAMP_FILE}" |
| 41 | git rev-parse HEAD >> "${TIMESTAMP_FILE}" |
| 42 | whoami >> "${TIMESTAMP_FILE}" |
| 43 | |
| 44 | # Found I had to do a lazy force unmount ("-l" flag) to make it work reliably |
| 45 | sudo umount -l "${PARTITION}" |
| 46 | rmdir "${PARTITION}" |