#!/bin/bash
echo "Armbian 'linux-image-current-sunxi64' for '6.1.38-sunxi64': 'prerm' starting."
set -e # Error control

function is_boot_dev_vfat() {
# When installing these packages during image build, /boot is not mounted, and will most definitely not be vfat.
# Use an environment variable to signal that it _will_ be a fat32, so symlinks are not created.
# This is passed by install_deb_chroot() explicitly via the runners.
if [[ "${ARMBIAN_IMAGE_BUILD_BOOTFS_TYPE:-"unknown"}" == "fat" ]]; then
echo "Armbian: ARMBIAN_IMAGE_BUILD_BOOTFS_TYPE: '${ARMBIAN_IMAGE_BUILD_BOOTFS_TYPE:-"not set"}'"
return 0
fi
if ! mountpoint -q /boot; then
return 1
fi
local boot_partition bootfstype
boot_partition=$(findmnt --nofsroot -n -o SOURCE /boot)
bootfstype=$(blkid -s TYPE -o value $boot_partition)
if [[ "$bootfstype" == "vfat" ]]; then
return 0
fi
return 1
}

#set -x # Debugging

export DEB_MAINT_PARAMS="$*" # Pass maintainer script parameters to hook scripts
export INITRD=Yes # Tell initramfs builder whether it's wanted
# Run the same hooks Debian/Ubuntu would for their kernel packages.
test -d /etc/kernel/prerm.d && run-parts --arg="6.1.38-sunxi64" --arg="/boot/vmlinuz-6.1.38-sunxi64" /etc/kernel/prerm.d

set +x # Disable debugging
echo "Armbian 'linux-image-current-sunxi64' for '6.1.38-sunxi64': 'prerm' finishing."
true
