Browse Source

memtest86-efi: added to repo

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
master
Steven Noonan 2 years ago
parent
commit
7b8367d69a
  1. 11
      memtest86-efi/.gitignore
  2. 52
      memtest86-efi/PKGBUILD
  3. 284
      memtest86-efi/memtest86-efi
  4. 10
      memtest86-efi/memtest86-efi-remove.hook
  5. 10
      memtest86-efi/memtest86-efi-update.hook
  6. 9
      memtest86-efi/memtest86-efi.conf
  7. 3
      memtest86-efi/memtest86-efi.install

11
memtest86-efi/.gitignore

@ -0,0 +1,11 @@
*
!.gitignore
!.SRCINFO
!PKGBUILD
!memtest86-efi
!memtest86-efi.conf
!memtest86-efi.install
!grub.conf
!systemd-boot.conf
!memtest86-efi-update.hook
!memtest86-efi-remove.hook

52
memtest86-efi/PKGBUILD

@ -0,0 +1,52 @@
# Maintainer: X0rg
_pkgbasename=memtest86
pkgname=$_pkgbasename-efi
pkgver=8.3
pkgrel=1
pkgdesc="A free, thorough, stand alone memory test as an EFI application"
arch=('any')
url="https://www.memtest86.com"
license=('GPL2' 'custom:PassMark')
makedepends=('p7zip')
optdepends=('efibootmgr: to add a new EFI boot entry'
'grub: to add MemTest86 entry in GRUB2 menu')
backup=(etc/$pkgname/$pkgname.conf)
install=$pkgname.install
source=(#"$pkgname-$pkgver.zip::https://www.memtest86.com/downloads/$_pkgbasename-usb.zip"
"$pkgname-$pkgver.zip::https://github.com/X0rg/AUR-packages/raw/master/files/$_pkgbasename-usb.zip"
"memtest86-efi"
"memtest86-efi.conf"
"memtest86-efi-update.hook"
"memtest86-efi-remove.hook")
sha512sums=('40fbe074a1e9b076a9329511cb444afd7eaecc4401173c05c66c464462ca70aa23e42f990d99ba526c65d7da51e0b45cd651b99406a9dcb15d51a11ce83550f4'
'9e4919d3a1d2435c3feed718b422be7206ec639268d79aee2ac419e9665d134829f507506da33903da547f73d22e0833335118cbe04cda0c5bbfc7e64aa3bd51'
'947df5f141bdb00a007a796c74f862d6ca41f74b4e5b28d1a444b4b8e538114e7f404f54420508639a77e554c2477ad324570ada0462c9fd7b058ed51e0ea8d8'
'6952376b601b84da5fba14a7a5316d37b6083bae20f68f5b90b22d2728a19bf6d1fb367cf1adecfb82bf03e339b7dbf91f6d23f0d59731f89cf45240f16d5614'
'1fe55a642e36005f5b7b58e5fb245e8029bb1a19b5f30d8ddba6bbf5a4b96c1bba35be0dfacee478034b8367fdde62d34a934dcd787f4c6702889615bac9f78a')
prepare() {
msg2 "Extract ISO..."
7z x -y "$srcdir/memtest86-usb.img" > /dev/null
7z x -y "$srcdir/EFI System Partition.img" -oc:"$srcdir/$pkgname-$pkgver" > /dev/null
}
package() {
cd "$srcdir/$pkgname-$pkgver"
msg2 "Move MemTest86 stuff in share directory..."
install -Dvm755 "EFI/BOOT/BOOTIA32.efi" "$pkgdir/usr/share/$pkgname/bootia32.efi"
install -Dvm755 "EFI/BOOT/BOOTX64.efi" "$pkgdir/usr/share/$pkgname/bootx64.efi"
install -Dvm644 "EFI/BOOT/blacklist.cfg" "$pkgdir/usr/share/$pkgname/blacklist.cfg"
install -Dvm644 "EFI/BOOT/mt86.png" "$pkgdir/usr/share/$pkgname/mt86.png"
install -Dvm644 "EFI/BOOT/unifont.bin" "$pkgdir/usr/share/$pkgname/unifont.bin"
install -Dvm644 "license.rtf" "$pkgdir/usr/share/licenses/$pkgname/LICENSE.rtf"
msg2 "Install AUR provided script..."
install -Dvm755 "$srcdir/memtest86-efi" "$pkgdir/usr/bin/memtest86-efi"
install -Dvm644 "$srcdir/memtest86-efi.conf" "$pkgdir/etc/memtest86-efi/memtest86-efi.conf"
msg2 "Install Pacman hooks..."
install -Dvm644 "$srcdir/memtest86-efi-update.hook" "$pkgdir/usr/share/libalpm/hooks/memtest86-efi-update.hook"
install -Dvm644 "$srcdir/memtest86-efi-remove.hook" "$pkgdir/usr/share/libalpm/hooks/memtest86-efi-remove.hook"
}

284
memtest86-efi/memtest86-efi

@ -0,0 +1,284 @@
#!/bin/bash
export LC_ALL=C
CE="\033[31m" # Color red
CB="\033[1m" # Color bold
CR="\033[0m" # Color reset
PRGNAME=$(basename $0)
CONFDIR="/etc/memtest86-efi"
CONFFILE="$CONFDIR/memtest86-efi.conf"
source "$CONFFILE" || exit 127
shopt -s extglob
[[ "$(uname -m)" == "i686" ]] && ARCH="ia32"
[[ "$(uname -m)" == "x86_64" ]] && ARCH="x64"
warn() {
echo -e "${CB}${CE}This script is unofficial, written by an AUR (Arch User Repository) user. Use it at YOUR OWN RISK.${CR}"
}
checkuid() {
if [[ $EUID -ne 0 ]]; then
echo -e "${CE}You must be root to run $PRGNAME. Aborted.${CR}" > /dev/stderr
exit -1
fi
}
checkcommand() {
if ! $1 &> /dev/null; then
echo -e "${CE}Command $1 not found. Aborted.${CR}" > /dev/stderr
exit 3
fi
}
_common_install() {
efidir="$1"
efifile="$2"
echo -e "MemTest86 is installed into ${CB}$efidir/${CR} directory."
mkdir -pv "$efidir"
cp -v "$MEMTEST86_PATH/"!(*.efi) "$efidir/" # Move files in memtest ESP directory
cp -v "$MEMTEST86_PATH/boot$ARCH.efi" "$efidir/$efifile" # Copy and rename .efi file
}
_write_grub_cfg() {
uuid="$1"
cat > "/etc/grub.d/86_memtest" <<FOE
#!/bin/sh
cat <<EOF
if [ "\\\$grub_platform" = "efi" ]; then
menuentry "Memtest86" {
search --set=root --no-floppy --fs-uuid $uuid
chainloader /EFI/memtest86/memtest$ARCH.efi
}
fi
EOF
FOE
chmod 755 "/etc/grub.d/86_memtest"
}
_write_systemd_boot_cfg() {
systemdbootdir="$1"
cat > "$systemdbootdir/memtest86-efi.conf" <<FOE
title MemTest86
efi /EFI/memtest86/memtest$ARCH.efi
FOE
}
install() {
if [[ $install == 1 ]]; then
echo "MemTest86 is already installed in ESP. Nothing to do." > /dev/stderr
exit 1
fi
# Find ESP device number
partition=$(fdisk -l | grep "EFI System" | awk '{print $1}' | tail -n1)
echo -en "Press Enter if ${CB}$partition${CR} is your ESP partition, "
echo -en "else enter device path manually (like ${CB}/dev/sdXY${CR}): "
read choice
[[ -n $choice ]] && partition=$choice
partnumber=$(echo $partition | grep -Eo '[0-9]+$')
[[ $partition == "/dev/nvme"* ]] && device=$(echo $partition | cut -dp -f1) || device=${partition//$partnumber}
# Find ESP mount point
esp=$(mount | grep $partition | awk '{print $3}' | tail -n1)
echo -en "Press Enter if ${CB}$esp${CR} is your mount point, "
echo -en "else enter mount point manually (like ${CB}/boot/efi${CR}): "
read choice
[[ -n $choice ]] && esp=$choice
# Check if ESP is mounted
if ! mount | grep $partition | grep -q $esp; then
echo -e "ESP ${CB}$partition${CR} is not mounted, mounting..."
if ! mount "$partition" "$esp"; then
echo -e "${CE}Fail to mount $partition on $esp. Aborted.${CR}" > /dev/stderr
exit 2
fi
fi
echo -e "The target is: ${CB}$partition${CR} (mounted on ${CB}$esp${CR}).\n"
# Get user choice
echo "Select $PRGNAME action to perform:"
echo -e "${CB}1${CR}: Copy shellx64.efi file on ESP's root (bit safe)"
echo -e "${CB}2${CR}: Add a new EFI boot entry (more safe)"
echo -e "${CB}3${CR}: Add a boot entry for GRUB2 menu"
echo -e "${CB}4${CR}: Add a boot entry for systemd-boot menu"
echo -e "${CB}5${CR}: Cancel"
choice=0
while [[ $choice < 1 ]] || [[ $choice > 5 ]]; do
read choice
echo
done
case $choice in
1) # Install MemTest86 in $esp/
[[ -f "$esp/shell$ARCH.efi" ]] && mv -v "$esp/shell$ARCH.efi" "$esp/shell$ARCH.efi.bak" # Backup if exist
_common_install "$esp" "shell$ARCH.efi"
;;
2) # Install MemTest86 in $esp/EFI/memtest86/ & add an EFI boot entry
checkcommand efibootmgr
_common_install "$esp/EFI/memtest86" "memtest$ARCH.efi"
echo -e "\nAdd a new EFI boot entry..."
efibootmgr -c -d ${device} -p ${partnumber} -w -L "MemTest86" -l "\EFI\memtest86\memtest$ARCH.efi" # Manage efi entry
;;
3) # Install MemTest86 in $esp/EFI/memtest86/ & add a file for GRUB2
checkcommand grub-mkconfig
if [[ ! -d "/etc/grub.d/" ]]; then
echo -e "${CE}GRUB2 seems not installed on your system. Aborted.${CR}" > /dev/stderr
exit 2
fi
_common_install "$esp/EFI/memtest86" "memtest$ARCH.efi"
echo -e "\nAdd a new configuration file for GRUB..."
uuid=$(blkid $partition -s UUID -o value)
_write_grub_cfg "$uuid"
grub-mkconfig -o "/boot/grub/grub.cfg"
;;
4) # Install MemTest86 in $esp/EFI/memtest86/ & add a file for systemd-boot
checkcommand bootctl
_common_install "$esp/EFI/memtest86" "memtest$ARCH.efi"
echo -e "\nAdd a new configuration file for systemd-boot..."
systemdbootdir="$esp/loader/entries"
mkdir -pv "$systemdbootdir"
_write_systemd_boot_cfg "$systemdbootdir"
bootctl --path="$esp" update
;;
*) # Do nothing and quit
echo -e "Canceled. MemTest86 will not be installed."
exit 0
;;
esac
echo "Writting configuration..."
sed -i "s|@PARTITION@|$partition|g" "$CONFFILE"
sed -i "s|@ESP@|$esp|g" "$CONFFILE"
sed -i "s|@CHOICE@|$choice|g" "$CONFFILE"
sed -i "s|install=0|install=1|g" "$CONFFILE"
echo -e "\nMemTest86 has been installed in ESP."
}
update() {
if [[ $install == 0 ]]; then
echo "MemTest86 is not installed in ESP: it cannot be updated." > /dev/stderr
exit 1
fi
case $choice in
1) # Update files in $esp/
_common_install "$esp" "shell$ARCH.efi"
;;
2|3|4) # Update files in $esp/EFI/memtest86/
_common_install "$esp/EFI/memtest86" "memtest$ARCH.efi"
;;
esac
echo -e "\nMemTest86 has been updated in ESP."
}
remove() {
if [[ $install == 0 ]]; then
echo "MemTest86 is not installed in ESP: it cannot be removed." > /dev/stderr
exit 1
fi
case $choice in
1) # Remove files in $esp/
echo -e "MemTest86 will be removed from ${CB}$esp/${CR}."
rm -v "$esp/shell$ARCH.efi" "$esp/blacklist.cfg" "$esp/mt86.png" "$esp/unifont.bin"
[[ -f "$esp/shell$ARCH.efi.bak" ]] && mv -v "$esp/shell$ARCH.efi.bak" "$esp/shell$ARCH.efi"
;;
2) # Remove files in $esp/EFI/memtest86/ & delete EFI boot entry
checkcommand efibootmgr
echo -e "MemTest86 will be removed from ${CB}$esp/EFI/memtest86/${CR}."
rm -rfv "$esp/EFI/memtest86/"
echo -e "\nRemove MemTest86 EFI boot entry..."
entry=$(efibootmgr | grep MemTest86 | cut -c 5-8)
[[ -n $entry ]] && efibootmgr -b $entry -B
;;
3) # Remove files in $esp/EFI/memtest86/ & delete file for GRUB2
checkcommand grub-mkconfig
echo -e "MemTest86 will be removed from ${CB}$esp/EFI/memtest86/${CR}."
rm -rfv "$esp/EFI/memtest86/"
echo -e "\nRemove configuration file for GRUB..."
rm -v "/etc/grub.d/86_memtest"
grub-mkconfig -o "/boot/grub/grub.cfg"
;;
4) # Remove files in $esp/EFI/memtest86/ & delete file for systemd-boot
echo -e "MemTest86 will be removed from ${CB}$esp/EFI/memtest86/${CR}."
rm -rfv "$esp/EFI/memtest86/"
echo -e "\nRemove configuration file for systemd-boot..."
rm -v "$esp/loader/entries/memtest86-efi.conf"
;;
esac
echo "Writting configuration..."
sed -i "s|$partition|@PARTITION@|g" "$CONFFILE"
sed -i "s|$esp|@ESP@|g" "$CONFFILE"
sed -i "s|$choice|@CHOICE@|g" "$CONFFILE"
sed -i "s|install=1|install=0|g" "$CONFFILE"
echo -e "\nMemTest86 has been removed from ESP."
}
status() {
echo -e "${CB}Default MemTest86 directories:${CR}"
echo -e "Configuration directory: $CONFDIR/"
echo -e "Data directory: $MEMTEST86_PATH/\n"
if [[ $install == 0 ]]; then
echo -e "${CB}MemTest86 is not installed on your system.${CR}"
exit 1
else
echo -e "${CB}MemTest86 is installed on your system with following parameters:${CR}"
echo -e "ESP device name: $partition"
echo -e "ESP mount point: $esp"
echo -e "Type of installation: $choice"
exit 0
fi
}
help() {
echo -e "Usage: $PRGNAME ACTION\n"
echo -e "Available ACTION:"
echo -e "\t-i, --install\t Install MemTest86 in ESP"
echo -e "\t-u, --update\t Update an existing installation of MemTest86"
echo -e "\t-r, --remove\t Remove MemTest86 from ESP"
echo -e "\t-s, --status\t Print and return status"
echo -e "\t-h, --help\t Print this help and exit"
echo -e "\t-a, --about\t Print informations about $PRGNAME and exit"
}
about() {
echo -e "MemTest86 is a stand alone memory testing software, it cannot be run under an operating system."
echo -e "$PRGNAME is a script which helps you to easily use MemTest86 with your UEFI, as an EFI application."
}
if [[ -z $ARCH ]]; then
echo -e "${CE} Unsupported ARCH: $(uname -m). Aborted.${CR}" > /dev/stderr
exit -1
fi
case "$1" in
-i|--install) warn; checkuid; install; exit 0;;
-u|--update) checkuid; update; exit 0;;
-r|--remove) checkuid; remove; exit 0;;
-s|--status) status;;
-h|--help) help; exit 0;;
-a|--about) warn; about; exit 0;;
*) help; exit 1;;
esac

10
memtest86-efi/memtest86-efi-remove.hook

@ -0,0 +1,10 @@
[Trigger]
Operation = Remove
Type = File
Target = /usr/share/memtest86-efi/bootia32.efi
Target = /usr/share/memtest86-efi/bootx64.efi
[Action]
Description = Removing MemTest86 EFI from ESP
When = PostTransaction
Exec = /usr/bin/memtest86-efi --remove

10
memtest86-efi/memtest86-efi-update.hook

@ -0,0 +1,10 @@
[Trigger]
Operation = Upgrade
Type = File
Target = /usr/share/memtest86-efi/bootia32.efi
Target = /usr/share/memtest86-efi/bootx64.efi
[Action]
Description = Updating MemTest86 EFI into ESP
When = PostTransaction
Exec = /usr/bin/memtest86-efi --update

9
memtest86-efi/memtest86-efi.conf

@ -0,0 +1,9 @@
#
# /etc/memtest86-efi.conf
#
MEMTEST86_PATH=/usr/share/memtest86-efi
partition=@PARTITION@
esp=@ESP@
choice=@CHOICE@
install=0

3
memtest86-efi/memtest86-efi.install

@ -0,0 +1,3 @@
post_install() {
echo -e "You can use command \033[4mmemtest86-efi --install\033[0m as root to install MemTest86 in your ESP."
}
Loading…
Cancel
Save