From 30d2f304395a2908c50ab215c501d4085428167b Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 21 Aug 2024 17:22:24 +0200 Subject: add removal of entries --- genefi.sh | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'genefi.sh') diff --git a/genefi.sh b/genefi.sh index 5e3ad14..dc3e876 100755 --- a/genefi.sh +++ b/genefi.sh @@ -4,24 +4,48 @@ version () { } generate () { - efi_path=/efi/EFI/Linux - cd $efi_path + local efi_path=/efi/EFI/Linux - select efi_file in *; do break; done; + cd $efi_path + + PS3="Select the efi file: " + select efi_file in *.efi; do break; done; echo "creating EFI entry for $efi_file" readarray -d "-" -t file_arr <<< $efi_file - kernel_version=${file_arr[1]} + local kernel_version=${file_arr[1]} echo "recognized kernel version $kernel_version" - efi_label="gentoo-$kernel_version" + local efi_label="gentoo-$kernel_version" echo "assigned label '$efi_label'" - doas efibootmgr --create --disk=/dev/nvme0n1 --part=1 --label="$efi_label" --loader="\\EFI\\Linux\\$efi_file" --unicode + doas efibootmgr --create --disk=/dev/nvme0n1 --part=1 --label="$efi_label" --loader="\\EFI\\Linux\\$efi_file" --unicode >> /dev/null } -if [[ "$1" = "-v" ]] || [[ "$1" = "-V" ]] || [[ "$1" = "--version" ]]; then - version "0.2.0" -else +remove () { + readarray -d '\n' -t boot_entries <<< $( efibootmgr --unicode | grep -o -E " gentoo-[0-9]+.[0-9]+.[0-9]+" ) + PS3="Select the entry to delete: " + select boot_entry in $boot_entries; do break; done; + local boot_num="$(efibootmgr --unicode | grep "$boot_entry" | grep -o -E "^Boot[0-9]+" | grep -o -E "[0-9]+")" + echo "delete entry $boot_entry (Boot$boot_num)" + doas efibootmgr --unicode -B -b $boot_num >> /dev/null +} + +case $1 in +"-v" | "--version" | "-V") + version "0.3.0" +;; +"generate") + generate +;; +"remove") + remove +;; +"") generate -fi + remove +;; +*) + echo unknown argument +;; +esac -- cgit v1.2.3