#!/bin/bash

# omarchy:summary=Overwrite the user config for the Limine bootloader and rebuild it.
# omarchy:requires-sudo=true

# A Mac that has yet to activate Limine can still have its tools installed.
if [[ $(omarchy-boot-backend) != "limine" ]]; then
  echo "There is no active Limine config to reset"
else
  legacy_uki="/boot/EFI/Linux/$(cat /etc/machine-id)_linux.efi"

  if sudo test -f /boot/EFI/Linux/omarchy_linux.efi && sudo test -f "$legacy_uki"; then
    echo "Cleanup extra UKI"
    sudo rm -f "$legacy_uki"
  fi
  echo "Resetting limine config"

  sudo mv /boot/limine.conf /boot/limine.conf.bak

  sudo cp "$OMARCHY_PATH/default/limine/limine.conf" /boot/limine.conf

  sudo limine-update
  sudo limine-snapper-sync
fi
