2021-02-08 14:50:20 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
ROOT_DIR="$(dirname "$(readlink -f "$0")")"
|
|
|
|
OUT_DIR="${1:-$(pwd)}"
|
|
|
|
|
|
|
|
TMP_DIR="$(mktemp --directory)"
|
|
|
|
TMP_DIR_PFS="$(mktemp --directory)"
|
|
|
|
TMP_DIR_MOUNT="$(mktemp --directory)"
|
|
|
|
|
|
|
|
TOOLS=(git make sudo qemu-aarch64-static xz)
|
|
|
|
|
|
|
|
GIT_REPO=https://github.com/void-linux/void-mklive.git
|
|
|
|
GIT_REV=f71eb4bb81004b50884011ef5e0d00f99bc2892a
|
|
|
|
GIT_DIR="$ROOT_DIR/.void-mklive"
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
cleanup_mounts
|
|
|
|
sudo rm -r "$TMP_DIR" "$TMP_DIR_PFS" "$TMP_DIR_MOUNT"
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup_mounts() {
|
|
|
|
sudo losetup -D
|
|
|
|
sudo umount --recursive "$TMP_DIR_MOUNT" || true
|
|
|
|
}
|
|
|
|
|
|
|
|
check_tools() {
|
2021-02-09 17:47:27 +00:00
|
|
|
for tool in "${TOOLS[@]}"; do
|
2021-02-08 14:50:20 +00:00
|
|
|
if ! command -v "$tool" &> /dev/null
|
|
|
|
then
|
|
|
|
echo "$tool could not be found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
init_void_mklive() {
|
|
|
|
if [ ! -d "$GIT_DIR" ]; then
|
|
|
|
git clone "$GIT_REPO" "$GIT_DIR"
|
|
|
|
cd "$GIT_DIR" && git checkout "$GIT_REV"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd "$GIT_DIR"
|
|
|
|
|
|
|
|
if [ "$(git rev-parse HEAD)" != "$GIT_REV" ]; then
|
|
|
|
git fetch
|
|
|
|
git checkout "$GIT_REV"
|
|
|
|
fi
|
|
|
|
|
|
|
|
make
|
|
|
|
sed -i 's/ROOTFS_TARBALL#void-/ROOTFS_TARBALL#*void-/g' "$GIT_DIR/mkimage.sh"
|
|
|
|
}
|
|
|
|
|
|
|
|
build_img() {
|
|
|
|
local rootfs_file="$TMP_DIR/rootfs.tar.xz"
|
|
|
|
local platformfs_file="$TMP_DIR/void-pinebookpro-PLATFORMFS.tar.xz"
|
|
|
|
local img="$TMP_DIR/void-pbp.img"
|
|
|
|
|
|
|
|
cd "$GIT_DIR"
|
|
|
|
|
|
|
|
sudo ./mkrootfs.sh -o "$rootfs_file" aarch64
|
2021-02-10 20:09:50 +00:00
|
|
|
sudo ./mkplatformfs.sh -p "dracut lvm2 cryptsetup dbus NetworkManager" -o "$platformfs_file" pinebookpro "$rootfs_file"
|
|
|
|
sudo ./mkimage.sh -B 256MiB -s 3GB -o "$img" "$platformfs_file"
|
2021-02-08 14:50:20 +00:00
|
|
|
|
2021-02-09 17:47:27 +00:00
|
|
|
# shellcheck disable=SC2024
|
|
|
|
# it is correct that the decompressed image is written as the unprivileged user
|
2021-02-08 14:50:20 +00:00
|
|
|
sudo xz --decompress --stdout "$img.xz" > "$img"
|
2021-02-09 17:47:27 +00:00
|
|
|
|
|
|
|
local loop_dev
|
|
|
|
loop_dev="$(sudo losetup --show -f -P "$img")"
|
2021-02-08 14:50:20 +00:00
|
|
|
|
|
|
|
sudo mount "$loop_dev"p2 "$TMP_DIR_MOUNT"
|
|
|
|
sudo mount "$loop_dev"p1 "$TMP_DIR_MOUNT"/boot
|
|
|
|
|
|
|
|
sudo cp "$ROOT_DIR/bootstrap" "$TMP_DIR_MOUNT/usr/bin/bootstrap"
|
|
|
|
sudo chmod +x "$TMP_DIR_MOUNT/bin/bootstrap"
|
|
|
|
|
|
|
|
sudo cp "$(which qemu-aarch64-static)" "$TMP_DIR_MOUNT/usr/bin/"
|
|
|
|
|
|
|
|
sudo chroot "$TMP_DIR_MOUNT" qemu-aarch64-static /bin/bash <<"EOT"
|
2021-02-10 20:09:50 +00:00
|
|
|
ln -s /etc/sv/dbus /etc/runit/runsvdir/default/
|
|
|
|
ln -s /etc/sv/NetworkManager /etc/runit/runsvdir/default/
|
2021-02-08 14:50:20 +00:00
|
|
|
EOT
|
|
|
|
|
|
|
|
sudo rm "$TMP_DIR_MOUNT/usr/bin/qemu-aarch64-static"
|
|
|
|
cleanup_mounts
|
|
|
|
|
|
|
|
mkdir -p "$OUT_DIR"
|
2021-02-09 17:47:27 +00:00
|
|
|
xz --threads=0 --compress --stdout "$img" > "$OUT_DIR/$(basename "$img.xz")"
|
2021-02-08 14:50:20 +00:00
|
|
|
|
2021-02-09 17:47:27 +00:00
|
|
|
echo "built pinebookpro image: $OUT_DIR/$(basename "$img.xz")"
|
2021-02-08 14:50:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup 0 SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
|
|
|
|
|
|
|
|
check_tools
|
|
|
|
init_void_mklive
|
|
|
|
build_img
|