Austin Schuh | ab8c0c5 | 2020-02-22 13:42:37 -0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -xe |
| 4 | |
| 5 | IMAGE="2020-02-13-raspbian-buster-lite.img" |
| 6 | PARTITION="2020-02-13-raspbian-buster-lite.img.partition" |
| 7 | HOSTNAME="pi-8971-1" |
| 8 | |
| 9 | function target() { |
| 10 | HOME=/root/ USER=root sudo proot -0 -q qemu-arm-static -w / -r "${PARTITION}" "$@" |
| 11 | } |
| 12 | |
| 13 | function user_pi_target() { |
| 14 | USER=root sudo proot -0 -q qemu-arm-static -w / -r "${PARTITION}" sudo -h 127.0.0.1 -u pi "$@" |
| 15 | } |
| 16 | |
| 17 | OFFSET="$(fdisk -lu "${IMAGE}" | grep "${IMAGE}2" | awk '{print 512*$2}')" |
| 18 | mkdir -p "${PARTITION}" |
| 19 | |
| 20 | if mount | grep "${PARTITION}" >/dev/null ; |
| 21 | then |
| 22 | echo "Already mounted" |
| 23 | else |
| 24 | echo "Mounting" |
| 25 | sudo mount -o loop,offset=${OFFSET} "${IMAGE}" "${PARTITION}" |
| 26 | fi |
| 27 | |
| 28 | sudo cp target_configure.sh "${PARTITION}/tmp/" |
| 29 | sudo cp dhcpcd.conf "${PARTITION}/tmp/dhcpcd.conf" |
| 30 | sudo cp change_hostname.sh "${PARTITION}/tmp/change_hostname.sh" |
| 31 | |
| 32 | target /bin/mkdir -p /home/pi/.ssh/ |
| 33 | cat ~/.ssh/id_rsa.pub | target tee /home/pi/.ssh/authorized_keys |
| 34 | |
| 35 | target /bin/bash /tmp/target_configure.sh |
| 36 | |
| 37 | # Run a prompt as root inside the target to poke around and check things. |
| 38 | target /bin/bash --rcfile /root/.bashrc |
| 39 | |
| 40 | sudo umount "${PARTITION}" |
| 41 | rmdir "${PARTITION}" |