Jim Ostrowski | 814d281 | 2022-12-11 23:17:14 -0800 | [diff] [blame] | 1 | #!/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 | |
| 6 | set -e |
| 7 | |
| 8 | MOUNT_PT="tmp_mount" |
| 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 | PARTITION="${MOUNT_PT}.partition" |
| 18 | |
| 19 | mkdir -p "${PARTITION}" |
| 20 | sudo mount "${DEVICE}2" "${PARTITION}" |
| 21 | |
| 22 | function target() { |
| 23 | HOME=/root/ USER=root sudo proot -0 -q qemu-aarch64-static -w / -r "${PARTITION}" "$@" |
| 24 | } |
| 25 | |
| 26 | if [ "${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" |
| 29 | else |
| 30 | target /root/bin/change_hostname.sh "${1}" |
| 31 | fi |
| 32 | |
| 33 | |
| 34 | echo "Starting a shell for any manual configuration" |
| 35 | target /bin/bash --rcfile /root/.bashrc |
| 36 | |
| 37 | # Found I had to do a lazy force unmount ("-l" flag) to make it work reliably |
| 38 | sudo umount -l "${PARTITION}" |
| 39 | rmdir "${PARTITION}" |