blob: 4c50a6bde962ebf701ebbb651103d50a74993ac1 [file] [log] [blame]
Jim Ostrowskic58989a2022-01-29 16:12:08 -08001#!/bin/bash
2
3set -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
Austin Schuhf7970ca2022-02-11 22:19:29 -08007ORIG_IMAGE="2022-01-28-raspios-bullseye-arm64-lite.img"
Jim Ostrowskic58989a2022-01-29 16:12:08 -08008IMAGE=`echo ${ORIG_IMAGE} | sed s/.img/-frc-mods.img/`
9DEVICE="/dev/sda"
10
11if mount | grep "${DEVICE}" >/dev/null ;
12then
13 echo "Overwriting a mounted partition, is ${DEVICE} the sd card?"
14 exit 1
15fi
16
17sudo dd if=${IMAGE} of=${DEVICE} bs=1M status=progress
18
19PARTITION="${IMAGE}.partition"
20
21mkdir -p "${PARTITION}"
22sudo mount "${DEVICE}2" "${PARTITION}"
23
24function target() {
Austin Schuhf7970ca2022-02-11 22:19:29 -080025 HOME=/root/ USER=root sudo proot -0 -q qemu-aarch64-static -w / -r "${PARTITION}" "$@"
Jim Ostrowskic58989a2022-01-29 16:12:08 -080026}
27
28if [ "${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"
31else
32 target /root/bin/change_hostname.sh "${1}"
33fi
34
Jim Ostrowskic58989a2022-01-29 16:12:08 -080035# Put a timestamp on when this card got created and by whom
36TIMESTAMP_FILE="${PARTITION}/home/pi/.DiskFlashedDate.txt"
Jim Ostrowski2a483b32022-02-15 18:19:14 -080037echo "Date Imaged: "`date` > "${TIMESTAMP_FILE}"
38echo "Image file: ${IMAGE}" >> "${TIMESTAMP_FILE}"
39echo "Git tag: "`git rev-parse HEAD` >> "${TIMESTAMP_FILE}"
40echo "User: "`whoami` >> "${TIMESTAMP_FILE}"
Jim Ostrowskic58989a2022-01-29 16:12:08 -080041
Jim Ostrowskif1dbbe12022-02-12 16:19:49 -080042echo "Starting a shell for any manual configuration"
43target /bin/bash --rcfile /root/.bashrc
44
Jim Ostrowskic58989a2022-01-29 16:12:08 -080045# Found I had to do a lazy force unmount ("-l" flag) to make it work reliably
46sudo umount -l "${PARTITION}"
47rmdir "${PARTITION}"