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

KERNEL_NAME=-veyron
KERNEL_VERSION=3.14.0-1-ARCH

flash_kernel() {
  major=$(mountpoint -d / | cut -f 1 -d ':')
  minor=$(mountpoint -d / | cut -f 2 -d ':')
  device=$(cat /proc/partitions | awk {'if ($1 == "'${major}'" && $2 == "'${minor}'") print $4 '})
  device="/dev/${device/%2/1}"

  echo "A new kernel version needs to be flashed onto ${device}."
  echo "Do you want to do this now? [y|N]"
  read -r shouldwe
  if [[ $shouldwe =~ ^([yY][eE][sS]|[yY])$ ]]; then
    dd if=/boot/vmlinux.kpart of=${device}
    sync
  else
    echo "You can do this later by running:"
    echo "# dd if=/boot/vmlinux.kpart of=${device}"
  fi
}

post_install () {
  # updating module dependencies
  echo ">>> Updating module dependencies. Please wait ..."
  depmod ${KERNEL_VERSION}
  flash_kernel
}

post_upgrade() {
  # updating module dependencies
  echo ">>> Updating module dependencies. Please wait ..."
  depmod ${KERNEL_VERSION}
  flash_kernel
}