#!/bin/sh
set -e

if test -e /boot/memtest86.bin ; then
  if [ -f /usr/lib/grub/grub-mkconfig_lib ]; then
    . /usr/lib/grub/grub-mkconfig_lib
    LX=linux16
  elif [ -f /usr/lib/grub/update-grub_lib ]; then
    . /usr/lib/grub/update-grub_lib
    LX=linux
  else
    # no grub file, so we notify and exit gracefully
    echo "Cannot find grub config file, exiting." >&2
    exit 0
  fi

  MEMTESTPATH=$( make_system_path_relative_to_its_root "/boot/memtest86.bin" )
  echo "Found memtest86 image: $MEMTESTPATH" >&2
  cat << EOF
menuentry "Memory test (memtest86)" {
	$LX	$MEMTESTPATH
}
EOF
fi
