#!/bin/sh

# shellcheck disable=SC2034,SC3043,SC1091,SC2154

## style-ok: no-strict
set -o errexit
set -o nounset

# grub-mkconfig helper script.
# Copyright (C) 2020  Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.

prefix="/usr"
exec_prefix="/usr"
datarootdir="/usr/share"

export TEXTDOMAIN=grub
export TEXTDOMAINDIR="${datarootdir}/locale"

## nounset OFF around this source, and only around it.
##
## grub-mkconfig_lib is GRUB's OWN upstream library and is not written for
## nounset. It reads '${grub_probe}', which grub-mkconfig sets as a plain shell
## variable and NEVER exports -- and generators run as separate processes, so
## they do not inherit it. Under 'set -u' the library therefore aborts on its
## own line 27, taking this generator with it and dropping the UEFI Firmware
## Settings boot entry.
##
## Measured, not assumed: with errexit and nounset and no guard, running this
## under the environment grub-mkconfig actually provides fails with
##   grub-mkconfig_lib: 27: grub_probe: parameter not set
set +o nounset
. "${pkgdatadir}/grub-mkconfig_lib"
set -o nounset

LABEL="UEFI Firmware Settings"

gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2

cat << EOF
if [ "\$grub_platform" = "efi" ]; then
	menuentry '${LABEL}' \$menuentry_id_option 'uefi-firmware' {
		fwsetup
	}
fi
EOF
