#!/bin/bash
if [ "$EUID" -ne 0 ]; then
  echo "Run this script as root."
  exit 1
fi

efibootmgr -v | grep -i 'File(\\EFI\\Microsoft\\Boot\\bootmgfw.efi)' | while read -r line; do
    bootnum=$(echo "$line" | grep -oP 'Boot\K[0-9A-Fa-f]{4}')
    echo "Deleted Windows Boot Manager entry"
    efibootmgr -b "$bootnum" -B
done

delete_efivar() {
  local pattern="$1"
  for var in /sys/firmware/efi/efivars/$pattern; do
    [ -e "$var" ] && chattr -i "$var" && rm "$var" && echo "Deleted $var"
  done
}
# known efivars created by Windows, can be updated in future
delete_efivar "OfflineUniqueIDEKPubCRC-eaec226f-c9a3-477a-a826-ddc716cdc0e3"
delete_efivar "OfflineUniqueIDEKPub-eaec226f-c9a3-477a-a826-ddc716cdc0e3"
delete_efivar "UnlockIDCopy-eaec226f-c9a3-477a-a826-ddc716cdc0e3"
delete_efivar "BugCheck*-ba57e015-65b3-4c3c-b274-659192f699e3"
delete_efivar "PBRDevicePath-a9b5f8d2-cb6d-42c2-bc01-b5ffaae4335e"
