63 lines
1.6 KiB
Bash
63 lines
1.6 KiB
Bash
#!/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
|
|
rootfs=$1
|
|
|
|
if [[ "$rootfs" != *rootfs* ]]; then
|
|
echo >&2 "!! Filename '${rootfs}' does not look like a rootfs filename"
|
|
return 2
|
|
fi
|
|
|
|
|
|
local booted other
|
|
booted=$(awk '$2 == "/run/umorpha-root/root"{print $1}' </proc/mounts)
|
|
booted=${booted##*_}
|
|
if [[ $booted == a ]]; then
|
|
other=b
|
|
else
|
|
other=a
|
|
fi
|
|
|
|
echo ":: Installing '${rootfs}' to slot '$other'"
|
|
|
|
v rm -f -- "/boot/grub/grub_$other.cfg"
|
|
|
|
if [[ -e /dev/mapper/vg_umorpha-lv_root_$other ]]; then
|
|
v lvresize --size="$(stat -c '%s' -- "$rootfs")b" "/dev/mapper/vg_umorpha-lv_root_$other"
|
|
else
|
|
v lvcreate --zero=y --wipesignatures=y --yes --name="lv_root_$other" \
|
|
--size="$(stat -c '%s' -- "$rootfs")b" vg_umorpha
|
|
fi
|
|
v pv -- "$rootfs" >"/dev/mapper/vg_umorpha-lv_root_$other"
|
|
|
|
{
|
|
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" <<-EOF
|
|
|
|
v arch-chroot -- "$tmpdir/mnt" sh -c "printf '%s\n' usr/lib/modules/*/vmlinuz | /usr/share/libalpm/scripts/mkinitcpio install"
|
|
}
|
|
|
|
main "$@"
|