#!/usr/bin/env bash # Copyright (C) 2023 Umorpha Systems # SPDX-License-Identifier: AGPL-3.0-or-later set -euE -o pipefail v() { printf >&2 ' $ %s\n' "${*@Q}" "$@" } main() { local rootfs size case "$1" in *rootfs*) rootfs="$1" size=$(stat -c '%s' -- "$rootfs") ;; --stdin=*) rootfs=/dev/stdin size=${1#--stdin=} ;; *) echo >&2 "!! Filename '${1}' does not look like a rootfs filename" return 2 ;; esac local booted other booted=$(awk '$2 == "/run/umorpha-root/root"{print $1}' "/dev/mapper/vg_umorpha-lv_root_$other" else v pv -- "$rootfs" >"/dev/mapper/vg_umorpha-lv_root_$other" fi { for krnl in "$tmpdir/mnt"/usr/lib/modules/*/vmlinuz; do pkgbase=$(cat -- ${krnl%vmlinuz}pkgbase) cat <<-EOF menuentry 'Parabola GNU/Linux-libre, ${pkgbase} kernel' set search --no-floppy --fs-uuid --set=root ${selector_boot#UUID=} echo 'Loading ${pkgbase} kernel...' linux /vmlinuz-${pkgbase} root=$selector_root overlay_root=$selector_overlay boot=$selector_boot rw echo 'Loading initial ramdisk...' initrd /initramfs-${pkgbase}.img echo 'Booting...' boot EOF done } | install -Dm600 /dev/stdin "/boot/grub/grub_a.cfg" v arch-chroot -- "$tmpdir/mnt" sh -c "printf '%s\n' usr/lib/modules/*/vmlinuz | /usr/share/libalpm/scripts/mkinitcpio install" } main "$@"