## arg 1:  the new package version
## arg 2:  the old package version
post_upgrade() {
  echo "Intel CPU ucode upgrades are no longer performed by the firmware loader."
  echo "If you want to update the Intel CPU ucode on boot, add the file"
  echo "Make sure you enable the 'microcode' hook in /etc/mkinitcpio.conf"
  echo "And regenerate kernel image with mkinitcpio"
  echo ""
  if [ "$(vercmp $2 20151106)" -lt 0 ]; then
    echo "If you're previously using grub, make sure you generate the new grub config file."
  fi

  if [ -f /boot/grub/grub.cfg ]; then
    if grep -q intel-ucode.img /boot/grub/grub.cfg; then
       printf "\e[01;31mYour grub.cfg contains intel-ucode.img\n"
       if which grub-mkconfig >/dev/null 2>&1; then
         printf "Trying to automatically update grub.cfg...\n"
         printf "Backup current grub.cfg at /boot/grub/grub.cfg.bak\n"
         cp /boot/grub/grub.cfg /boot/grub/grub.cfg.bak
         if grub-mkconfig -o /boot/grub/grub.cfg.new; then
            mv /boot/grub/grub.cfg.new /boot/grub/grub.cfg
	    printf "\e[01;32mgrub.cfg successfully updated. You can check it at /boot/grub/grub.cfg.\n\e[00m"
         else
	    printf "Failed to update grub.cfg. Make sure you regenerate it with:\n"
	    printf "  grub-mkconfig -o /boot/grub/grub.cfg\n\e[00m"
         fi
       fi
    fi
  fi

  if which mkinitcpio >/dev/null 2>&1; then
    echo ">>> Generating initial ramdisk, using mkinitcpio.  Please wait..."
    echo ">>> If you are using non-default kernel, you should update kernel"
    echo ">>> manually"
    if [ -f etc/mkinitcpio.d/linux-CHAKRA.preset ]; then
      mkinitcpio -p linux-CHAKRA
    fi
    if [ -f etc/mkinitcpio.d/linux-CHAKRA-LTS.preset ]; then
      mkinitcpio -p linux-CHAKRA-LTS
    fi
  fi
}
