#!/bin/bash
echo "Armbian 'linux-headers-legacy-sunxi64' for '5.15.120-sunxi64': 'preinst' 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

if [[ -d "/usr/src/linux-headers-5.15.120-sunxi64" ]]; then
echo "Cleaning pre-existing directory /usr/src/linux-headers-5.15.120-sunxi64 ..."
rm -rf "/usr/src/linux-headers-5.15.120-sunxi64"
fi

set +x # Disable debugging
echo "Armbian 'linux-headers-legacy-sunxi64' for '5.15.120-sunxi64': 'preinst' finishing."
true
