blob: 6673808875f48edbbc61e823d3c23f7d9f16bf85 [file] [log] [blame]
Jim Ostrowski814d2812022-12-11 23:17:14 -08001#!/bin/bash
2
3### Helper script to mount a Raspberry Pi SD card
4### Optionally run change_hostname if given pi name as argument
5
6set -e
7
8MOUNT_PT="tmp_mount"
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
17PARTITION="${MOUNT_PT}.partition"
18
19mkdir -p "${PARTITION}"
20sudo mount "${DEVICE}2" "${PARTITION}"
21
22function target() {
23 HOME=/root/ USER=root sudo proot -0 -q qemu-aarch64-static -w / -r "${PARTITION}" "$@"
24}
25
26if [ "${1}" == "" ]; then
27 echo "No hostname specified, so skipping setting it."
28 echo "You do this manually on the pi by running /root/bin/change_hostname.sh PI_NAME"
29else
30 target /root/bin/change_hostname.sh "${1}"
31fi
32
33
34echo "Starting a shell for any manual configuration"
35target /bin/bash --rcfile /root/.bashrc
36
37# Found I had to do a lazy force unmount ("-l" flag) to make it work reliably
38sudo umount -l "${PARTITION}"
39rmdir "${PARTITION}"