#!/bin/bash

set -e

case $1 in
  preinst)
    exit 0
    ;;
  postinst)
    echo "Running for kernel ${VERSION}"

    mkinitramfs ${VERSION}
    grub-mkconfig -o /boot/grub/grub.cfg

    if [ ! -f /etc/modprobe.d/usb.conf ]; then
      cp /usr/share/linux-${VERSION}/usb.conf /etc/modprobe.d/usb.conf
    fi
    ;;
  prerm)
    exit 0
    ;;
  postrm)
    if [ -f /boot/initrd.img-${VERSION} ]; then
      rm /boot/initrd.img-${VERSION}
    fi

    grub-mkconfig -o /boot/grub/grub.cfg
    ;;
esac
