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