#!/bin/sh -efu
# if memtest86/memtest86+ is installed as a part of base system,
# its %post is effectively skipped (installkernel won't run with
# DURING_INSTALL set -- which is the case for first and second
# installation stages)
# thanks led@ for the simpler implementation suggestion

. install2-init-functions

# Find most fresh memtest version.
MEMTEST="$(find $destdir/boot/ -mindepth 1 -maxdepth 1 -name 'memtest-*.bin' -printf '%f\n' |sort -u |tail -n1)"
[ -n "$MEMTEST" ] || exit 0

MEMTEST="${MEMTEST#memtest-}"
MEMTEST="${MEMTEST%.bin}"

# Use "memtest" label iff it is not already used,
# to lessen translation fuzz in boot menu.
DURING_INSTALL= exec_chroot installkernel --label memtest -m "$MEMTEST"
