#!/bin/sh -efu
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2023  Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org>

PROG="${PROG:-${0##*/}}"

message()
{
	printf '%s: %s\n' "$PROG" "$*" >&2
}

fatal()
{
	message "$*"
	exit 1
}

# This helper function attempts to locate the default kernel, and if it
# is unavailable, it will match *any* installed kernel instead.
# If the kernel image cannot be found at all, the variable will remain empty.
find_vmlinuz()
{
	if [ -L /boot/vmlinuz ]; then
		set -- "$1" "$(readlink -ev /boot/vmlinuz)"
	else
		set -- "$1" "$(find /boot -maxdepth 1 -type f -name 'vmlinuz-*' -print -quit)"
	fi
	eval "$1=\"\$2\""
}
