#!/bin/fish # get id and type of last snapshot set -l config "root" set -l snapshot (snapper -c $config --jsonout ls | jq -c ".$config | last") set -l id (echo $snapshot | jq ".number") if not contains (echo $snapshot | jq -r ".type") "pre" "post" echo "==> last snapshot type is neither 'pre' nor 'post'; no UKI creation" exit end # check if UKI already exists set -l ukis (ls /boot/EFI/Linux/ | grep "snap-pac-uki-[1-9][0-9]*\.efi" | grep -o '[1-9][0-9]*') if contains $id $ukis echo "==> UKI already exists; no UKI creation" exit end # prepare uki creation set -l buildpath "/tmp/snap-pac-uki/$id" mkdir -p $buildpath rm -rf "$buildpath/*" cd $buildpath sed "s/BUILD_ID=.*/BUILD_ID=\"Snapshot $id\"/" ./os-release grep options /boot/loader/entries/00-arch.conf | \ string sub -s 9 | \ sed ':a;N;$!ba;s/\n/ /g' | \ sed "s/subvol=@/subvol=@snapshots\\/$id\\/snapshot/" >./kernel-parameters # create uki set -l ukipath "/boot/EFI/Linux/snap-pac-uki-$id.efi" objcopy \ --add-section .osrel="./os-release" --change-section-vma .osrel=0x20000 \ --add-section .cmdline="./kernel-parameters" --change-section-vma .cmdline=0x30000 \ --add-section .splash="/usr/share/systemd/bootctl/splash-arch.bmp" --change-section-vma .splash=0x40000 \ --add-section .linux="/boot/vmlinuz-linux" --change-section-vma .linux=0x2000000 \ --add-section .initrd="/boot/initramfs-linux.img" --change-section-vma .initrd=0x3000000 \ "/usr/lib/systemd/boot/efi/linuxx64.efi.stub" $ukipath echo "==> created UKI: $ukipath"