#!/bin/sh -e

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

read -r host 2>/dev/null <"/etc/klapki/host" || read -r host 2>/dev/null <"/etc/machine-id" || host="$(hostname)"
hostvar="/sys/firmware/efi/efivars/${host}-a8a9ad3a-f831-11ea-946d-674ccd7415cc"
[ -f "$hostvar" ] || exit 0

image_path="$2"
[ -n "$image_path" ] || image_path="/boot/vmlinuz-$1"
set -- "$1" "$image_path"

[ -f "/boot/initrd.img-$1" ] && set -- "$@" "/boot/initrd.img-$1" || :

exec klapki addkernel "$@" ""
