#!/usr/bin/env bash

readonly SCRIPT_NAME="limine-reset-enroll"
readonly AUTH_HELPER=/usr/lib/limine/auth-helper
readonly LIMINE_FUNCTIONS_PATH=/usr/lib/limine/limine-common-functions

if ((EUID != 0)); then
	if [[ -f "${AUTH_HELPER}" ]]; then
		# shellcheck disable=SC1090
		source "${AUTH_HELPER}" || exit
	else
		echo -e "\033[91m${SCRIPT_NAME} must be run as root.\033[0m" >&2
		exit 1
	fi
fi

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

initialize_header || exit 1
reset_enroll_config
