compatibility with alpine shell
parent
a8f2f3e498
commit
7e84c4e31a
21
build-rpi.sh
21
build-rpi.sh
|
@ -1,29 +1,35 @@
|
|||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
|
||||
# Extracts the rootfs from OpenWRT Raspberry Pi image available from
|
||||
# https://downloads.openwrt.org/releases/19.07.2/targets/brcm2708/bcm2708/
|
||||
# https://downloads.openwrt.org/releases/19.07.3/targets/brcm2708/bcm2708/
|
||||
# and builds a Docker container out of it
|
||||
#
|
||||
# Refer to https://openwrt.org/toh/raspberry_pi_foundation/raspberry_pi
|
||||
# to choose the right image
|
||||
#
|
||||
# If building on x86, you must have qemu-arm and binfmt-support installed
|
||||
set -e
|
||||
set -ex
|
||||
|
||||
IMG=${1:-'x'}
|
||||
IMG=${1:-'image.img'}
|
||||
|
||||
check_uid() {
|
||||
if [[ $(id -u) -ne 0 ]]; then
|
||||
echo "this script must be run as root"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
mount_rootfs() {
|
||||
echo "* mounting image"
|
||||
offset=$(sfdisk -d ${IMG} | grep "${IMG}2" | sed -E 's/.*start=\s+([0-9]+).*/\1/g')
|
||||
tmpdir=$(mktemp -u -p .)
|
||||
mkdir -p "${tmpdir}"
|
||||
sudo mount -o loop,offset=$((512 * $offset)) -t ext4 ${IMG} ${tmpdir}
|
||||
mount -o loop,offset=$((512 * $offset)) -t ext4 ${IMG} ${tmpdir}
|
||||
}
|
||||
|
||||
docker_build() {
|
||||
echo "* building Docker image"
|
||||
sudo docker build \
|
||||
docker build \
|
||||
--build-arg ROOT_PW="${ROOT_PW}" \
|
||||
-t ${BUILD_TAG} -f Dockerfile.rpi ${tmpdir}
|
||||
}
|
||||
|
@ -31,10 +37,11 @@ docker_build() {
|
|||
|
||||
cleanup() {
|
||||
echo "* cleaning up"
|
||||
sudo umount ${tmpdir}
|
||||
umount ${tmpdir} || true
|
||||
rm -rf ${tmpdir}
|
||||
}
|
||||
|
||||
check_uid
|
||||
test -f ${IMG} || { echo 'no image file found'; exit 1; }
|
||||
trap cleanup EXIT
|
||||
mount_rootfs
|
||||
|
|
Loading…
Reference in New Issue