2024-02-26 23:38:25 +00:00
|
|
|
#!/bin/bash
|
2024-02-26 23:57:44 +00:00
|
|
|
# Copyright (C) 2024 Umorpha Systems
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2024-02-26 23:38:25 +00:00
|
|
|
|
|
|
|
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
|
2024-02-26 23:57:44 +00:00
|
|
|
|
2024-02-26 23:38:25 +00:00
|
|
|
################################################################################
|
|
|
|
|
2024-02-26 23:57:44 +00:00
|
|
|
outfile="$1"
|
2024-02-26 23:38:25 +00:00
|
|
|
|
2024-02-26 23:57:44 +00:00
|
|
|
################################################################################
|
2024-02-26 23:38:25 +00:00
|
|
|
|
2024-02-26 23:57:44 +00:00
|
|
|
truncate --size=2G "$outfile"
|
2024-02-26 23:38:25 +00:00
|
|
|
|
2024-02-26 23:57:44 +00:00
|
|
|
parted --script "$outfile" -- mklabel gpt
|
2024-02-26 23:38:25 +00:00
|
|
|
|
2024-02-26 23:57:44 +00:00
|
|
|
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"
|
2024-02-26 23:38:25 +00:00
|
|
|
|
2024-02-26 23:57:44 +00:00
|
|
|
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"
|
2024-02-26 23:38:25 +00:00
|
|
|
|
2024-02-26 23:57:44 +00:00
|
|
|
parted --script "$outfile" -- set 1 boot on
|
2024-02-26 23:38:25 +00:00
|
|
|
|
2024-02-26 23:57:44 +00:00
|
|
|
loopdev=$(sudo losetup --find --show --partscan -- "$outfile")
|
2024-02-26 23:38:25 +00:00
|
|
|
cleanup+=("sudo losetup --detach ${loopdev@Q}")
|
|
|
|
|
|
|
|
sudo mkfs.ext4 -F -O ^metadata_csum,^64bit "${loopdev}p1"
|
|
|
|
|
2024-02-26 23:57:44 +00:00
|
|
|
mountpoint=$(mktemp -dt "${0##*/}.XXXXXXXXXX")
|
|
|
|
cleanup+=("rm -rf -- ${mountpoint@Q}")
|
|
|
|
sudo mount "${loopdev}p1" "$mountpoint"
|
|
|
|
cleanup+=("sudo umount ${mountpoint@Q}")
|
2024-02-26 23:38:25 +00:00
|
|
|
|
2024-02-26 23:57:44 +00:00
|
|
|
osi-mk \
|
2024-02-26 23:38:25 +00:00
|
|
|
--conf=format=dir --conf=bootloader=none --edit \
|
|
|
|
--package=base \
|
|
|
|
--package=linux-libre \
|
|
|
|
--package=uboot4extlinux-orangepi_one \
|
2024-02-26 23:57:44 +00:00
|
|
|
"$mountpoint"
|
2024-02-26 23:38:25 +00:00
|
|
|
|
2024-02-26 23:57:44 +00:00
|
|
|
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
|