# arg 1:  the new package version
# arg 2:  the old package version

KERNEL_NAME=-espressobin
KERNEL_VERSION=4.12.0-1-ARCH

post_install () {
  # updating module dependencies
  echo ">>> Updating module dependencies. Please wait ..."
  depmod ${KERNEL_VERSION}
  echo ">>> Generating initial ramdisk, using mkinitcpio. Please wait..."
  mkinitcpio -p linux${KERNEL_NAME}
  if [[ -e "/boot/initramfs-linux.img" ]]; then
    mkimage -n "Ramdisk Image" -A arm64 -O linux -T ramdisk -C none -d /boot/initramfs-linux.img /boot/initramfs-linux.uimg > /dev/null
  fi
}

post_upgrade() {
  if findmnt --fstab -uno SOURCE /boot &>/dev/null && ! mountpoint -q /boot; then
    echo "WARNING: /boot appears to be a separate partition but is not mounted."
  fi

  # updating module dependencies
  echo ">>> Updating module dependencies. Please wait ..."
  depmod ${KERNEL_VERSION}
  echo ">>> Generating initial ramdisk, using mkinitcpio. Please wait..."
  mkinitcpio -p linux${KERNEL_NAME}
  if [[ -e "/boot/initramfs-linux.img" ]]; then
    mkimage -n "Ramdisk Image" -A arm64 -O linux -T ramdisk -C none -d /boot/initramfs-linux.img /boot/initramfs-linux.uimg > /dev/null
  fi
}

post_remove() {
  rm -f boot/initramfs-linux.{img,uimg}
}