#!/bin/bash
# Filename:      ${GRML_FAI_CONFIG}/media-scripts/GRMLBASE/41-memtest
# Purpose:       Install memtest86+ program files
# Authors:       grml-team (grml.org)
# Bug-Reports:   see http://grml.org/bugs/
# License:       This file is licensed under the GPL v2 or any later version.
################################################################################

set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}
# shellcheck source=/dev/null
. "$GRML_LIVE_CONFIG"

if [ -n "$NO_ADDONS" ] ; then
  echo "I: skipping memtest86+ installation as \$NO_ADDONS is set."
  exit 0
fi

echo "I: installing memtest86+."

media_dir="${target}/${GRML_LIVE_MEDIADIR}"
mkdir -p "${media_dir}/boot/addons"

# memtest86+ >=8.00-1. The binary can be booted in UEFI or BIOS mode.
if ifclass AMD64 ; then
  grml-live-copy-file-logged "${media_dir}"/boot/addons/memtest86+x64.efi "${target}" /boot/mt86+x64 || true
  grml-live-copy-file-logged "${media_dir}"/boot/addons/memtest "${target}" /boot/mt86+x64 || true
elif ifclass I386 ; then
  grml-live-copy-file-logged "${media_dir}"/boot/addons/memtest86+ia32.efi "${target}" /boot/mt86+ia32 || true
  grml-live-copy-file-logged "${media_dir}"/boot/addons/memtest "${target}" /boot/mt86+ia32 || true
fi

# memtest86+ >=6.00-1. Separate binaries for UEFI and BIOS mode.
if ifclass AMD64 ; then
  grml-live-copy-file-logged "${media_dir}"/boot/addons/memtest86+x64.efi "${target}" /boot/memtest86+x64.efi || true
  grml-live-copy-file-logged "${media_dir}"/boot/addons/memtest "${target}" /boot/memtest86+x64.bin || true
elif ifclass I386 ; then
  grml-live-copy-file-logged "${media_dir}"/boot/addons/memtest86+ia32.efi "${target}" /boot/memtest86+ia32.efi || true
  grml-live-copy-file-logged "${media_dir}"/boot/addons/memtest "${target}" /boot/memtest86+ia32.bin || true
fi

## END OF FILE #################################################################
# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2
