61 lines
1.5 KiB
Bash
Executable File
61 lines
1.5 KiB
Bash
Executable File
#!/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 msdos \
|
|
mkpart primary ext4 1M 100% \
|
|
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 \
|
|
--fmt=dir --edit \
|
|
--arch=armv7h \
|
|
--conf=bootloader=none \
|
|
--package=base \
|
|
--package=linux-libre \
|
|
--package=uboot4extlinux-orangepi_one \
|
|
--module=modules/umorpha-sshusers.sh \
|
|
--module=modules/base-arm.sh \
|
|
--module=modules/base-net.sh \
|
|
"$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
|