2009-04-24 17:33:51 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# package name
|
|
|
|
PNAME="memtest86+"
|
|
|
|
|
2016-02-23 16:02:36 +00:00
|
|
|
# binary image
|
|
|
|
BNAME="memtest86+"
|
|
|
|
|
|
|
|
# ELF image
|
|
|
|
ELFNAME="elf-$BNAME"
|
|
|
|
|
|
|
|
# executable image to be installed
|
|
|
|
ENAME="$ELFNAME"
|
2009-04-24 17:33:51 +00:00
|
|
|
|
2014-08-26 12:19:26 +00:00
|
|
|
# GRUB 2 template
|
2011-12-07 14:48:31 +00:00
|
|
|
G2TEMPL="20_memtest86+"
|
2011-12-05 14:19:53 +00:00
|
|
|
|
2016-02-23 16:02:36 +00:00
|
|
|
# GRUB 2 environment file
|
|
|
|
CONF_FILE="/etc/memtest86+.conf"
|
|
|
|
|
|
|
|
# GRUB2 environment variable to control image type
|
|
|
|
CONF_VAR="INSTALL_ELF"
|
|
|
|
|
|
|
|
# whether to install ELF image
|
|
|
|
ELF=1
|
|
|
|
|
2014-08-26 12:19:26 +00:00
|
|
|
if [ "$1" = "--help" -o "$1" = "-h" ]; then
|
|
|
|
cat <<:EOF
|
2014-09-05 08:51:42 +00:00
|
|
|
usage: memtest-setup [OPTIONS]
|
|
|
|
|
2014-08-26 12:19:26 +00:00
|
|
|
This utility installs Memtest86+ into your GRUB boot loader menu.
|
|
|
|
It supports both GRUB 2 and GRUB Legacy (i.e. GRUB 0.9x).
|
|
|
|
In case of GRUB 2 it installs GRUB 2 template into /etc/grub.d and GRUB 2
|
|
|
|
config needs to be regenerated manually by running:
|
|
|
|
|
2014-09-05 08:51:42 +00:00
|
|
|
grub2-mkconfig -o /boot/grub2/grub.cfg
|
2014-08-26 12:19:26 +00:00
|
|
|
|
|
|
|
This is not done automatically because it could overwrite any custom changes
|
|
|
|
in /boot/grub2/grub.cfg.
|
2014-09-05 08:51:42 +00:00
|
|
|
|
|
|
|
OPTIONS:
|
2016-02-23 16:02:36 +00:00
|
|
|
-e , --elf installs ELF image (the default)
|
|
|
|
-b , --bin installs binary image (non-ELF)
|
2014-09-05 08:51:42 +00:00
|
|
|
-h , --help show this help
|
|
|
|
|
2014-08-26 12:19:26 +00:00
|
|
|
:EOF
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2016-02-23 16:02:36 +00:00
|
|
|
[ "$1" = "-b" -o "$1" = "--bin" ] && ELF=0
|
|
|
|
[ "$1" = "-e" -o "$1" = "--elf" ] && ELF=1
|
|
|
|
|
|
|
|
if [ "$ELF" = 1 ]; then
|
|
|
|
# BANNER_SUFFIX needs to be simultaneously changed also in grub2 template
|
|
|
|
BANNER_SUFFIX=
|
|
|
|
ENAME="$ELFNAME"
|
|
|
|
else
|
|
|
|
ELF=0
|
|
|
|
BANNER_SUFIX="(non-ELF)"
|
|
|
|
ENAME="$BNAME"
|
|
|
|
fi
|
|
|
|
|
2009-04-24 17:33:51 +00:00
|
|
|
if [ -d /sys/firmware/efi ]; then
|
|
|
|
echo "memtest86+ does not support EFI platforms."
|
|
|
|
exit 254
|
|
|
|
fi
|
|
|
|
|
2011-12-05 14:19:53 +00:00
|
|
|
if [ -f /boot/grub2/grub.cfg ]; then
|
2014-08-26 12:19:26 +00:00
|
|
|
echo "GRUB 2 detected, installing template..."
|
2011-12-05 14:19:53 +00:00
|
|
|
if [ ! -d /etc/grub.d ]; then
|
|
|
|
echo "ERROR: unable to find /etc/grub.d"
|
|
|
|
exit 253
|
|
|
|
fi
|
2016-02-23 16:02:36 +00:00
|
|
|
if [ ! -r /usr/share/memtest86+/$G2TEMPL ]; then
|
|
|
|
echo "ERROR: unable to find GRUB 2 template."
|
|
|
|
exit 251
|
2011-12-05 14:19:53 +00:00
|
|
|
fi
|
2016-02-23 16:02:36 +00:00
|
|
|
if ! cp /usr/share/memtest86+/$G2TEMPL /etc/grub.d; then
|
|
|
|
echo "ERROR: unable to copy GRUB 2 template, do you have write permission to"
|
|
|
|
echo "/etc/grub.d?"
|
|
|
|
# EX_IOERR
|
|
|
|
exit 74
|
|
|
|
fi
|
|
|
|
if [ ! -w "$CONF_FILE" ]
|
|
|
|
then
|
|
|
|
echo "ERROR: file '$CONF_FILE' is not writable."
|
|
|
|
exit 250
|
2011-12-05 14:19:53 +00:00
|
|
|
fi
|
|
|
|
chmod a+x /etc/grub.d/$G2TEMPL
|
2014-08-26 12:19:26 +00:00
|
|
|
echo "GRUB 2 template installed."
|
2011-12-05 14:19:53 +00:00
|
|
|
echo "Do not forget to regenerate your grub.cfg by:"
|
|
|
|
echo " # grub2-mkconfig -o /boot/grub2/grub.cfg"
|
|
|
|
else
|
|
|
|
MTVERSION=`rpm -q --qf '%{version}' $PNAME`
|
|
|
|
MTPATH="/boot/$ENAME-$MTVERSION"
|
2009-04-24 17:33:51 +00:00
|
|
|
|
2011-12-05 14:19:53 +00:00
|
|
|
MENT=`cat /boot/grub/grub.conf | grep "$ENAME-$MTVERSION"` &> /dev/null
|
|
|
|
if [ "$MENT" != "" ]; then
|
|
|
|
echo "$MTPATH is already configured. Exiting..."
|
|
|
|
exit 0
|
|
|
|
fi
|
2009-04-24 17:33:51 +00:00
|
|
|
|
2011-12-05 14:19:53 +00:00
|
|
|
if [ ! -f $MTPATH ]; then
|
|
|
|
echo "ERROR: $MTPATH does not exist."
|
|
|
|
exit 255
|
|
|
|
fi
|
2009-04-24 17:33:51 +00:00
|
|
|
|
2016-02-23 16:02:36 +00:00
|
|
|
/sbin/new-memtest-pkg --install $MTVERSION --banner="Memtest86+${BANNER_SUFFIX}" --kernel-name="$ENAME"
|
2011-12-05 14:19:53 +00:00
|
|
|
RETVAL="$?"
|
2009-04-24 17:33:51 +00:00
|
|
|
|
2011-12-05 14:19:53 +00:00
|
|
|
if [ "$RETVAL" != "0" ]; then
|
|
|
|
echo "ERROR: grubby failed to configure your bootloader for $MTPATH."
|
|
|
|
exit $RETVAL
|
|
|
|
else
|
2016-02-23 16:02:36 +00:00
|
|
|
[ "$ELF" = 1 ] && sed -i -e"s,kernel \(/boot\)\?/$ENAME,kernel --type=netbsd \1/$ENAME," /boot/grub/grub.conf
|
2011-12-05 14:19:53 +00:00
|
|
|
sed -i -e"s,/$ENAME-$MTVERSION.*,/$ENAME-$MTVERSION," /boot/grub/grub.conf
|
|
|
|
fi
|
2009-04-24 17:33:51 +00:00
|
|
|
fi
|
|
|
|
|
2016-02-23 16:02:36 +00:00
|
|
|
# update/add configuration variable to the configuration file
|
|
|
|
if grep -q "^\s*$CONF_VAR\s*=" "$CONF_FILE"
|
|
|
|
then
|
|
|
|
sed -i "/^\s*$CONF_VAR\s*=/ s/\(\s*$CONF_VAR\s*=[\"']\?\)[^\"']*\([\"']\?\s*\)/\1${ELF}\2/g" "$CONF_FILE"
|
|
|
|
else
|
|
|
|
echo "$CONF_VAR=\"$ELF\"" >> "$CONF_FILE"
|
|
|
|
fi
|
|
|
|
|
2009-04-24 17:33:51 +00:00
|
|
|
echo "Setup complete."
|