#! /bin/sh
set -e

# grub-mkconfig helper script.
# Copyright (C) 2011  Michal Ambroz <rebus@seznam.cz>
#
# 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.
#
# 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 the script.  If not, see <http://www.gnu.org/licenses/>.

prefix=/usr
exec_prefix=/usr
bindir=/usr/bin
grublibdir=/usr/share/grub
. ${grublibdir}/grub-mkconfig_lib

export TEXTDOMAIN=grub
export TEXTDOMAINDIR=${prefix}/share/locale

CLASS=""

IMAGE=memtest

if [ -f /boot/${IMAGE} ]; then
  if grub_file_is_not_garbage /boot/${IMAGE}; then
    echo "Found Memtest86+ image: /boot/${IMAGE}" >&2
#    printf "menuentry 'Memtest86+' {\n"
    if [ -z "${prepare_boot_cache}" ]; then
      prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
    fi
#    printf '%s\n' "${prepare_boot_cache}"

    message="$(gettext_printf "Loading %s %s ..." "Memtest86+" "")"
    rel_dirname=`make_system_path_relative_to_its_root /boot`
    cat << EOF
menuentry 'Memtest86+' {
${prepare_boot_cache}
	echo '$message'
	linux ${rel_dirname}/${IMAGE}
}
EOF
  fi
fi
