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

cd "/usr/src/linux-headers-5.15.120-sunxi64"
NCPU=$(grep -c 'processor' /proc/cpuinfo)
echo "Compiling kernel-headers tools (5.15.120-sunxi64) using $NCPU CPUs - please wait ..."
yes "" | make ARCH="arm64" oldconfig
make ARCH="arm64" -j$NCPU scripts
make ARCH="arm64" -j$NCPU M=scripts/mod/
# make ARCH="arm64" -j$NCPU modules_prepare # depends on too much other stuff.
echo "Done compiling kernel-headers tools (5.15.120-sunxi64)."
echo "Done compiling kernel-headers tools (5.15.120-sunxi64)."

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