-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
executable file
·60 lines (49 loc) · 1.77 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
#set -x
IMG_URL="http://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2022-01-28/2022-01-28-raspios-bullseye-armhf-lite.zip"
IMG_PATH="$HOME/dockerpi3_image"
FILENAME=$(basename $IMG_URL)
NAME=$(basename $IMG_URL .zip)
FILEPATH="${IMG_PATH}/${NAME}.img"
IMG_RESIZE="8G"
PROCESSORS="4"
if [ ! -d "${IMGPATH}" ]; then
mkdir -p ${IMG_PATH}
fi
if [ ! -f "${IMG_PATH}/${FILENAME}" ]
then
wget -O "${IMG_PATH}/${FILENAME}" "${IMG_URL}"
fi
if [ ! -f "${IMG_PATH}/${NAME}.img" ]
then
unzip -q "${IMG_PATH}/${FILENAME}" -d "${IMG_PATH}"
qemu-img resize -f raw "${FILEPATH}" "${IMG_RESIZE}"
# Find the first, DOS partition and mount it
BOOTSTART=`fdisk -l "${FILEPATH}" | sed -nr "s/^\S+1\s+([0-9]+).* c W95 FAT32 \(LBA\)$/\1/p"`
if [[ -z "${BOOTSTART}" ]]; then
echo "Can't find FAT32 first partition in image \"{$FILEPATH}\""
exit
fi
sudo losetup /dev/loop100 "${FILEPATH}" -o $((BOOTSTART*512))
sudo mkdir rpi-boot
sudo mount /dev/loop100 rpi-boot
# Make the change
if [[ -e "rpi-boot/ssh" ]]; then
echo "\"`basename "${FILEPATH}"`\" ALREADY had boot/ssh set."
else
sudo touch rpi-boot/ssh
echo "\"`basename "${FILEPATH}"`\" now has boot/ssh set."
fi
# Unmount and clear up
sudo umount rpi-boot
sudo rmdir rpi-boot
sudo losetup -d /dev/loop100
fi
# Start dockerpi3
docker run -p 5022:22 --rm -v "${IMG_PATH}/${NAME}.img":/sd.img \
--name rpi -it clutroth/dockerpi:vmlatest \
-m 1024 -smp ${PROCESSORS} -M raspi3 \
-kernel kernel8.img -dtb bcm2710-rpi-3-b-plus.dtb -sd /sd.img \
-append "console=ttyAMA0 root=/dev/mmcblk0p2 rw rootwait rootfstype=ext4" \
-nographic \
-device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::22-:22