#!/usr/bin/env bash

readonly LIMINE_FUNCTIONS_PATH=/usr/lib/limine/limine-common-functions

if [[ -f "${LIMINE_FUNCTIONS_PATH}" ]]; then
	# shellcheck disable=SC1090
	source "${LIMINE_FUNCTIONS_PATH}" || {
		echo "ERROR: Failed to source '${LIMINE_FUNCTIONS_PATH}'." >&2
		exit 1
	}
fi

check_limine_v12() {
	local version
	version="$(limine --version 2>/dev/null | head -n1)" || return 1
	[[ $version =~ ^Limine[[:space:]]+12\. ]]
}

warn_missing_verification_hashes() {
	check_secure_boot || return 0
	if [[ "${ENABLE_ENROLL_LIMINE_CONFIG:-}" == "yes" && "${ENABLE_VERIFICATION:-}" != "yes" ]] && check_limine_v12; then
		warning_msg "Secure Boot and config checksum enrollment are enabled. Limine v12 requires verification hashes for all loaded files except EFI chainload."
		info_msg "To disable this warning, manually add \"ENABLE_VERIFICATION=yes\" to /etc/default/limine, then rebuild the initramfs."
	fi
	return 0
}

warn_missing_verification_hashes
