summarylogtreecommitdiffstats
path: root/dracut-uefi-remove
blob: def8722bb0e6f819678117aeca15397b48d0db92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash -e

ESP_PATH=$(bootctl --print-esp-path)
MACHINE_ID=$(</etc/machine-id)
source <(grep '^BUILD_ID=' /etc/os-release)

while read -r line; do
  if [[ "$line" == 'usr/lib/modules/'+([^/])'/pkgbase' ]]; then
    read -r pkgbase < "/${line}"
    path="$(grep -lE "^${pkgbase}\$" /usr/lib/modules/*/pkgbase)"
    version=$(basename "${path%/pkgbase}")
    IMAGE="${ESP_PATH}/EFI/Linux/linux-${version}-${MACHINE_ID}-${BUILD_ID}.efi"
    if [ -f "$IMAGE" ]; then
      echo "==> Removing $IMAGE..."
      rm -f "$IMAGE"
    fi
  fi
done