#!/bin/sh
set -e

case "$1" in
  configure)
    # Ensure GRUB snippet is a file under /etc/default/grub.d/*.cfg
    if [ -f /etc/default/grub.d/saikyo.cfg/saikyo.cfg ]; then
      mkdir -p /etc/default/grub.d || true
      rm -f /etc/default/grub.d/saikyo.cfg || true
      cat /etc/default/grub.d/saikyo.cfg/saikyo.cfg > /etc/default/grub.d/saikyo.cfg || true
    fi

    if command -v update-grub >/dev/null 2>&1; then
      update-grub >/dev/null 2>&1 || true
    elif command -v update-grub2 >/dev/null 2>&1; then
      update-grub2 >/dev/null 2>&1 || true
    elif command -v grub-mkconfig >/dev/null 2>&1; then
      grub-mkconfig -o /boot/grub/grub.cfg >/dev/null 2>&1 || true
      grub-mkconfig -o /boot/grub2/grub.cfg >/dev/null 2>&1 || true
    fi
    ;;
esac

exit 0
