Add a script to flash and configure a pi rootfs
This automates all the settings for deploying, and also sets the
hostname to the provided argument. Much easier deployment.
Change-Id: Ic6773188753ca473c2a8cd35ce4bd76cd2826fdc
diff --git a/y2020/vision/rootfs/make_sd.sh b/y2020/vision/rootfs/make_sd.sh
new file mode 100755
index 0000000..eba47bc
--- /dev/null
+++ b/y2020/vision/rootfs/make_sd.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+set -e
+
+IMAGE="2020-08-20-raspios-buster-armhf-lite.img"
+DEVICE="/dev/sda"
+
+if mount | grep "${DEVICE}" >/dev/null ;
+then
+ echo "Overwriting a mounted partition, is ${DEVICE} the sd card?"
+ exit 1
+fi
+
+sudo dd if=${IMAGE} of=${DEVICE} bs=1M status=progress
+
+PARTITION="${IMAGE}.partition"
+
+mkdir -p "${PARTITION}"
+sudo mount "${DEVICE}2" "${PARTITION}"
+
+function target() {
+ HOME=/root/ USER=root sudo proot -0 -q qemu-arm-static -w / -r "${PARTITION}" "$@"
+}
+
+target /root/bin/change_hostname.sh "${1}"
+
+echo "Starting a shell for any manual configuration"
+target /bin/bash --rcfile /root/.bashrc
+
+sudo umount "${PARTITION}"