#!/bin/bash

set -e

case $1 in
  preinst)
    exit 0
    ;;
  postinst)
    if [[ ${TARGET} ]]; then
      echo "Running within ${TARGET} for kernel ${VERSION}"

      chroot ${TARGET} mkinitramfs ${VERSION}
      chroot ${TARGET} grub-mkconfig -o /boot/grub/grub.cfg
    else
      echo "Running for kernel ${VERSION}"

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

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