#!/bin/bash -e

# Play nice when run under debconf.
exec </dev/null >&2

abi=$1
target=/boot/firmware
dtb_dir=/usr/lib/linux-image-$abi/

        # The kernel image can be named either "Image" (standardized for ARM platforms) 
        #   or "vmlinuz-${abi}" (default naming convention for Linux kernels). We need
#   too support both conventions.
if [[ -f /boot/Image ]]; then
    cp /boot/Image ${target}/vmlinuz
elif [[ -f /boot/vmlinuz-${abi} ]]; then
    cp /boot/vmlinuz-${abi} ${target}/vmlinuz
else
    echo "Error: No kernel file (Image or vmlinuz-${abi}) found in /boot!"
    exit 1
fi

cp ${dtb_dir}/broadcom/*.dtb ${target}/
cp -r ${dtb_dir}/overlays ${target}/
sync -f ${target}/vmlinuz || true

exit 0
