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

create_config() {
  mkdir -p /boot/extlinux
  echo "LABEL Manjaro ARM
KERNEL /Image
FDT /dtbs/rockchip/rk3566-quartz64-a.dtb
APPEND initrd=/initramfs-linux.img console=ttyS2,1500000 root=LABEL=ROOT_MNJRO rw rootwait audit=0 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
}
