summarylogtreecommitdiffstats
path: root/dracut-remove.sh
blob: 6053edabb27b673226c97245c673e8786b379093 (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
28
29
#!/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/vmlinux-${pkgbase}"
		rm -f "/boot/initramfs-${pkgbase}.img"
		rm -f "/boot/initramfs-${pkgbase}-fallback.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