blob: 5f1a0e1734534fb0413eecbaa58fe5625d3d34a1 [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
35echo "Starting a shell for any manual configuration"
36target /bin/bash --rcfile /root/.bashrc
37
38# Put a timestamp on when this card got created and by whom
39TIMESTAMP_FILE="${PARTITION}/home/pi/.DiskFlashedDate.txt"
40date > "${TIMESTAMP_FILE}"
41git rev-parse HEAD >> "${TIMESTAMP_FILE}"
42whoami >> "${TIMESTAMP_FILE}"
43
44# Found I had to do a lazy force unmount ("-l" flag) to make it work reliably
45sudo umount -l "${PARTITION}"
46rmdir "${PARTITION}"