#!/bin/bash # Copyright (C) 2024 Umorpha Systems # SPDX-License-Identifier: AGPL-3.0-or-later set -euE -o pipefail cleanup=() _do_cleanup() { if [[ $? == 0 ]]; then echo ":: Cleaning up..." else echo >&2 "!! ERROR! Cleaning up..." fi for (( i=${#cleanup[@]}-1; i >= 0; i-- )); do eval "${cleanup[$i]}" done } trap '_do_cleanup' EXIT set -x ################################################################################ outfile="$1" ################################################################################ truncate --size=2G "$outfile" parted --script "$outfile" -- mklabel gpt parted --script "$outfile" -- mkpart 8192b $((1024*1024))b parted --script "$outfile" -- type 1 3DE21764-95BD-54BD-A5C3-4ABE786F38A8 # U-Boot parted --script "$outfile" -- name 1 "U-Boot" parted --script "$outfile" -- mkpart 1M 513M parted --script "$outfile" -- type 2 C12A7328-F81F-11D2-BA4B-00A0C93EC93B # EFI System Partition parted --script "$outfile" -- name 2 "EFI System Partition" parted --script "$outfile" -- set 1 boot on loopdev=$(sudo losetup --find --show --partscan -- "$outfile") cleanup+=("sudo losetup --detach ${loopdev@Q}") sudo mkfs.ext4 -F -O ^metadata_csum,^64bit "${loopdev}p1" mountpoint=$(mktemp -dt "${0##*/}.XXXXXXXXXX") cleanup+=("rm -rf -- ${mountpoint@Q}") sudo mount "${loopdev}p1" "$mountpoint" cleanup+=("sudo umount ${mountpoint@Q}") osi-mk \ --conf=format=dir --conf=bootloader=none --edit \ --package=base \ --package=linux-libre \ --package=uboot4extlinux-orangepi_one \ "$mountpoint" sudo arch-chroot "$mountpoint" \ /usr/lib/u-boot/uboot4extlinux-orangepi_one/install.sh "$loopdev" sudo arch-chroot "$mountpoint" \ install -Dm644 /usr/lib/u-boot/uboot4extlinux-orangepi_one/extlinux.conf /boot/extlinux/extlinux.conf