#!/bin/sh
set -e

case "$1" in
    configure)
        # AUTOMATICALLY GENERATED POST-INSTALL CODE

        GRUB_SRC_DIR=/usr/share/tuxedo-fix-nvidia-preserve-vram-suspend/grub.d
        GRUB_CFG_DIR=/etc/default/grub.d

        mkdir -p "$GRUB_CFG_DIR"

        for cfg in "$GRUB_SRC_DIR"/*-"tuxedo-fix-nvidia-preserve-vram-suspend".cfg; do
            [ -f "$cfg" ] || continue
            ln -sf "$cfg" "$GRUB_CFG_DIR/$(basename "$cfg")"
        done

        if [ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]; then
            echo "Running in chroot, do nothing."
        else
            grub-mkconfig -o /boot/grub/grub.cfg "$@"
        fi



        # END OF AUTOMATICALLY GENERATED POST-INSTALL CODE

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

exit 0
