#!/bin/sh

############## EASY Debian Linux UEFI setup ##############
#
# Moves latest kernel dracut EFI to Linux.efi
# To ease BIOS setup
#
# NOTE: By default EFI partition is mounted at /boot/efi          
#
### INSTALL
# 1) Place GIST at /etc/kernel/postinst.d/zz-update-efi
# 2) chmod +x /etc/kernel/postinst.d/zz-update-efi
# 3) apt install dracut
# 4) Create /etc/dracut.conf.d/10-debian.conf 
#
# hostonly=yes
#
# uefi=yes
# uefi_stub=/usr/lib/systemd/boot/efi/linuxx64.efi.stub
#
# 5) Setup your BIOS to boot /EFI/Linux/Linux.efi
###########################################################

LAST_KERNEL=$(ls /boot/efi/EFI/Linux | sort -V | tail -n 1)

if [ "$LAST_KERNEL" != "Linux.efi" ]; then
        echo "Found last kernel EFI ... "$LAST_KERNEL
        echo "mv "$LAST_KERNEL" to Linux.efi"

        mv /boot/efi/EFI/Linux/$LAST_KERNEL /boot/efi/EFI/Linux/Linux.efi
else
        echo "Current kernel is linked already"
fi