notice_uboot() {
  echo "New version of U-Boot firmware can be flashed to your microSD card"
  echo "or eMMC module.  You can do that by running:"
  echo "# dd if=/boot/idbloader.img of=/dev/mmcblkX seek=64 conv=notrunc,fsync"
  echo "# dd if=/boot/u-boot.itb of=/dev/mmcblkX seek=16384 conv=notrunc,fsync"
}

create_config() {
  mkdir -p /boot/extlinux
  echo "LABEL Manjaro ARM
KERNEL /Image
FDT /dtbs/rockchip/rk3399-pinephone-pro.dtb
APPEND initrd=/initramfs-linux.img console=ttyS2,1500000 root=LABEL=ROOT_MNJRO rw rootwait quiet splash plymouth.ignore-serial-consoles" > /boot/extlinux/extlinux.conf
}

post_install() {
  notice_uboot
  if [ -f /boot/extlinux/extlinux.conf.pacsave ]; then
    mv /boot/extlinux/extlinux.conf.pacsave /boot/extlinux/extlinux.conf
  fi
  if [ -f /boot/extlinux/extlinux.conf ]; then
    echo "Keeping old extlinux.conf file..."
  else
    create_config
  fi
}

post_upgrade() {
  notice_uboot
  if [ -f /boot/extlinux/extlinux.conf.pacsave ]; then
    mv /boot/extlinux/extlinux.conf.pacsave /boot/extlinux/extlinux.conf
  fi
  if [ -f /boot/extlinux/extlinux.conf ]; then
    echo "Keeping old extlinux.conf file..."
  else
    create_config
  fi
}

