summarylogtreecommitdiffstats
path: root/dracut-remove.sh
blob: 8f5167dc3e53ed9d8b993306d7a8cde7cb77b271 (plain)
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
#!/usr/bin/env bash

while read -r line; do
	if [[ "$line" == 'usr/lib/modules/'+([^/])'/pkgbase' ]]; then
		read -r pkgbase < "/${line}"
		rm -f "/boot/vmlinuz-${pkgbase}"
		rm -f "/boot/initramfs-${pkgbase}.img"

		# detect if the ESP directory is /boot or /efi
		efi_dirpath="/boot/EFI/Linux"
		if [ -d "/efi/EFI" ]; then
			efi_dirpath="/efi/EFI/Linux"
		fi

		# remove the efi file
		if [ -f "${efi_dirpath}/${pkgbase}.efi" ]; then
			sbctl remove-file "${efi_dirpath}/${pkgbase}.efi"
			rm -f "${efi_dirpath}/${pkgbase}.efi"
		fi

		# remove the efi fallback file
		if [ -f "${efi_dirpath}/${pkgbase}-fallback.efi" ]; then
			sbctl remove-file "${efi_dirpath}/${pkgbase}-fallback.efi"
			rm -f "${efi_dirpath}/${pkgbase}-fallback.efi"
		fi
	fi
done