#!/bin/sh -e

# https://kernel-team.pages.debian.net/kernel-handbook/ch-update-hooks.html
exec </dev/null >&2

host="$(cat "/etc/machine-id" || hostname)"
hostvar="/sys/firmware/efi/efivars/${host}-a8a9ad3a-f831-11ea-946d-674ccd7415cc"
[ -f "$hostvar" ] || exit 0

image_path="$2"
[ -z "$image_path" ] && image_path="/boot/vmlinuz-$1" || :

[ -f "/boot/initrd.img-$1" ] && initrd_path="/boot/initrd.img-$1" || initrd_path=""

exec klapki addkernel "$1" "$image_path" $initrd_path ""
