summaryrefslogtreecommitdiff
path: root/genefi.sh
blob: dc3e876ac3da1d2a73f2a73cf17a1a07ae427ac4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
version () {
	echo "genefi by fxqnlr v$1"
}

generate () {
	local efi_path=/efi/EFI/Linux

	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
	local kernel_version=${file_arr[1]}
	echo "recognized kernel version $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 >> /dev/null
}

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
	remove
;;
*)
	echo unknown argument
;;
esac