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

KERNEL_NAME=-amlogic-3.14-multiboot
KERNEL_VERSION=3.14.29

pre_install () {
  # backuo Image and uInitrd
  echo ">>> Backup Image and uInitrd. Please wait ..."
  mv /boot/uInitrd /boot/uInitrd.old
  mv /boot/Image /boot/Image.old
  mv /boot/dtbs /boot/dtbs.old
  mv /boot/s905_autoscript /boot/s905_autoscript.old
  mv /usr/lib/firmware /usr/lib/firmware.old
}

pre_upgrade () {
  # backuo Image and uInitrd
  echo ">>> Backup Image and uInitrd. Please wait ..."
  mv /boot/uInitrd /boot/uInitrd.old
  mv /boot/Image /boot/Image.old
  mv /boot/dtbs /boot/dtbs.old
  mv /boot/s905_autoscript /boot/s905_autoscript.old
  mv /usr/lib/firmware /usr/lib/firmware.old
}

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}
#  mkimage -A arm64 -T ramdisk -C none -n uInitrd -d /boot/initramfs-linux.img /boot/uInitrd
#  mkimage -A arm -O linux -T script -C none -d /boot/s905_autoscript.cmd /boot/s905_autoscript
  mv /boot/s905_autoscript.new /boot/s905_autoscript
}

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}
#  mkimage -A arm64 -T ramdisk -C none -n uInitrd -d /boot/initramfs-linux.img /boot/uInitrd
#  mkimage -A arm -O linux -T script -C none -d /boot/s905_autoscript.cmd /boot/s905_autoscript
  mv /boot/s905_autoscript.new /boot/s905_autoscript
}

post_remove() {
  # also remove the compat symlinks
  rm -f /boot/uInitrd
  rm -f /boot/dtbs
  rm -f /boot/s905_autoscript
  rm -f /usr/lib/firmware
}
