#!/usr/bin/env bash EFIPART="/boot" STUBSFOLDER="/" EFISTUBSLOC="$EFIPART/$STUBSFOLDER" ORIGIN="/boot" efidevice="$(findmnt -n -o SOURCE --target "$EFISTUBSLOC")" rootuuid=$(blkid -o value -s UUID "$(findmnt -n -o SOURCE --target "/")") cmdbase="ro quiet rd.luks.allow-discards rd.luks.uuid="af0f0b72-7895-4ce0-bfe4-967024fe3948" root=UUID=$rootuuid" function getDevice() { local device="$1" echo /dev/nvme0n1 } function getPartNumber() { echo 1 } function toWinPath() { echo $1 |sed -e "s,^/\+,,g" | sed -e "s,/,\\\\\\\\,g" } function findInitramfs() { local ver="$1" if [[ -f "$EFIPART/initramfs-$ver.img" ]] ; then echo initramfs-$ver.img else echo initramfs fi } shopt -s nullglob #if [[ ! "$(realpath "$ORIGIN")" == "$(realpath "$EFISTUBSLOC")" ]] ; then # for image in /boot/vmlinuz* ; do # if strings "$image" | grep -qi "EFI stub" ; then # mv "$image" "$EFISTUBSLOC/" # fi # done #fi echo for image in "$EFISTUBSLOC"/vmlinuz* ; do if echo "$image" | grep -q old || ! strings "$image" | grep -qi "EFI stub" ; then continue fi IFS='-' read base version <<< "$(basename "$image" | sed -e "s/\.efi//")" # version="${SPLIT[@]:1:5}" echo $version imagepath="$STUBSFOLDER/$(basename $image)" if ! efibootmgr | grep -q "$version" ; then efibootmgr -d "$(getDevice "$efidevice")" -p $(getPartNumber "$efidevice") --create --label "Gentoo Kernel $version" --loader "$(toWinPath "$imagepath")" -u "$cmdbase initrd=$(findInitramfs $version)" fi done