diff options
author | Xorg | 2022-02-05 12:41:24 +0100 |
---|---|---|
committer | Xorg | 2022-02-05 12:41:24 +0100 |
commit | 0933d59e69d94d6c4382a498da17195847846ee1 (patch) | |
tree | 78b1b7f4e26c7bcc6edd1a24215f69837e2868bc | |
parent | c82a3e48c20184e0d8856163a0c81af6d04141f3 (diff) | |
download | aur-0933d59e69d9.tar.gz |
Script: allow user to install MemTest86 in a specific directory
https://aur.archlinux.org/packages/memtest86-efi#comment-850382
-rw-r--r-- | .SRCINFO | 8 | ||||
-rw-r--r-- | PKGBUILD | 13 | ||||
-rw-r--r-- | memtest86-efi | 205 | ||||
-rw-r--r-- | memtest86-efi-remove.hook | 9 | ||||
-rw-r--r-- | memtest86-efi.conf | 8 | ||||
-rw-r--r-- | memtest86-efi.install | 54 |
6 files changed, 185 insertions, 112 deletions
@@ -1,7 +1,7 @@ pkgbase = memtest86-efi pkgdesc = A free, thorough, stand alone memory test as an EFI application pkgver = 9.4build1000 - pkgrel = 3 + pkgrel = 4 epoch = 1 url = https://www.memtest86.com install = memtest86-efi.install @@ -16,11 +16,9 @@ pkgbase = memtest86-efi source = memtest86-efi source = memtest86-efi.conf source = memtest86-efi-update.hook - source = memtest86-efi-remove.hook sha512sums = c5a6183e2b66fe6023a7478ddfecf94dab03e99272d916fe156f05e2edcc2e70c7cd12feff474381571213bd6b07c76b78dd54d07f2db011cbe3127dac2dc222 - sha512sums = 9379cb51d48a0858b51b604f66069959f75bf2f5b16416915b4a68701adb1086ff8a39a106f75c08908541ab3879c0d7e361f162fa1de2bd828d23ceeae190dd - sha512sums = 947df5f141bdb00a007a796c74f862d6ca41f74b4e5b28d1a444b4b8e538114e7f404f54420508639a77e554c2477ad324570ada0462c9fd7b058ed51e0ea8d8 + sha512sums = c797ddff498ca4263baf1b9af9d6704619671ea0f39b14e9b0a1c0497974de70bad316be790aa2e37481564333daa0afee19e20ba024ba7413e9d2a4a7772c69 + sha512sums = 5eb6231096484d8923fa9943401c5f5e654a498028b3b4c0b19d26c8265fd8882c94ee90dfa23fabcfb1f8d3812e0a502c195d57b4fbdf5cc25f3ac8dcb36759 sha512sums = a8936ed4a1955d69251955b824cfdfc606c374d40509a767ee4e357e746947d5bf1bd6793e5a4224733907556375bee05c0dd27f8044604f136d84c9be365d42 - sha512sums = 72220e2d5a055838bc347ac0266dd41d466d60186968b21f1782062c35f47f1fab544ad313cab9fac796e597c1f0095864ef38dbce7eee00bf53c336b38b34e6 pkgname = memtest86-efi @@ -4,7 +4,7 @@ _realname=memtest86 pkgname=$_realname-efi epoch=1 pkgver=9.4build1000 -pkgrel=3 +pkgrel=4 pkgdesc="A free, thorough, stand alone memory test as an EFI application" arch=('any') url="https://www.memtest86.com" @@ -17,13 +17,11 @@ install="$pkgname.install" source=("$pkgname-$pkgver.zip::https://github.com/X0rg/AUR-packages/raw/master/files/$_realname-$pkgver-usb.zip" "memtest86-efi" "memtest86-efi.conf" - "memtest86-efi-update.hook" - "memtest86-efi-remove.hook") + "memtest86-efi-update.hook") sha512sums=('c5a6183e2b66fe6023a7478ddfecf94dab03e99272d916fe156f05e2edcc2e70c7cd12feff474381571213bd6b07c76b78dd54d07f2db011cbe3127dac2dc222' - '9379cb51d48a0858b51b604f66069959f75bf2f5b16416915b4a68701adb1086ff8a39a106f75c08908541ab3879c0d7e361f162fa1de2bd828d23ceeae190dd' - '947df5f141bdb00a007a796c74f862d6ca41f74b4e5b28d1a444b4b8e538114e7f404f54420508639a77e554c2477ad324570ada0462c9fd7b058ed51e0ea8d8' - 'a8936ed4a1955d69251955b824cfdfc606c374d40509a767ee4e357e746947d5bf1bd6793e5a4224733907556375bee05c0dd27f8044604f136d84c9be365d42' - '72220e2d5a055838bc347ac0266dd41d466d60186968b21f1782062c35f47f1fab544ad313cab9fac796e597c1f0095864ef38dbce7eee00bf53c336b38b34e6') + 'c797ddff498ca4263baf1b9af9d6704619671ea0f39b14e9b0a1c0497974de70bad316be790aa2e37481564333daa0afee19e20ba024ba7413e9d2a4a7772c69' + '5eb6231096484d8923fa9943401c5f5e654a498028b3b4c0b19d26c8265fd8882c94ee90dfa23fabcfb1f8d3812e0a502c195d57b4fbdf5cc25f3ac8dcb36759' + 'a8936ed4a1955d69251955b824cfdfc606c374d40509a767ee4e357e746947d5bf1bd6793e5a4224733907556375bee05c0dd27f8044604f136d84c9be365d42') prepare() { 7z x -y "$srcdir/memtest86-usb.img" > /dev/null @@ -58,5 +56,4 @@ package() { # 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" } diff --git a/memtest86-efi b/memtest86-efi index b9ea6bfdfd2b..0e4c54b16053 100644 --- a/memtest86-efi +++ b/memtest86-efi @@ -10,15 +10,13 @@ CODE_PERM=2 # Invalid rights CODE_VALUE=3 # Bad value CODE_CMD=4 # Missing command CODE_FATAL=5 # Fatal error +ARCH="" PRGNAME=$(basename "$0") CONFDIR="/etc/memtest86-efi" CONFFILE="$CONFDIR/memtest86-efi.conf" # shellcheck source=/etc/memtest86-efi/memtest86-efi.conf source "$CONFFILE" || exit $CODE_FATAL shopt -s extglob -[[ "$(uname -m)" == "i686" ]] && ARCH="ia32" -[[ "$(uname -m)" == "x86_64" ]] && ARCH="x64" -[[ "$(uname -m)" == "aarch64" ]] && ARCH="aa64" warn() { echo -e "${CB}${CE}This script is unofficial, written by an AUR (Arch User Repository) user. Use it at YOUR OWN RISK.${CR}" @@ -26,14 +24,14 @@ warn() { checkuid() { if [[ $EUID -ne 0 ]]; then - echo -e "${CE}You must be root to run $PRGNAME. Aborted.${CR}" > /dev/stderr + echo -e "${CE}You must be root to run $PRGNAME. Aborted.${CR}" >&2 exit $CODE_PERM fi } checkcommand() { if ! $1 &> /dev/null; then - echo -e "${CE}Command $1 not found. Aborted.${CR}" > /dev/stderr + echo -e "${CE}Command $1 not found. Aborted.${CR}" >&2 exit $CODE_CMD fi } @@ -46,20 +44,20 @@ promptuser() { if [[ -n "$defaultvalue" ]] || [[ -n "$newvalue" ]]; then break else - echo -en "Please enter a valid value: " > /dev/stderr + echo -en "Please enter a valid value: " >&2 fi done [[ -n "$newvalue" ]] && echo "$newvalue" || echo "$defaultvalue" } _mount_esp() { - local partition="$1" - local esp="$2" + local esp_partition="$1" + local esp_mount_path="$2" - 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 + if ! grep -q "$esp_mount_path" "/proc/mounts"; then + echo -e "ESP ${CB}$esp_partition${CR} is not mounted, mounting..." + if ! mount "$esp_partition" "$esp_mount_path"; then + echo -e "${CE}Fail to mount $esp_partition on $esp_mount_path. Aborted.${CR}" >&2 exit $CODE_FATAL fi fi @@ -77,6 +75,7 @@ _common_install() { _write_grub_cfg() { local uuid="$1" + local loader_filename="$2" cat > "/etc/grub.d/86_memtest" <<FOE #!/bin/sh @@ -85,7 +84,7 @@ cat <<EOF if [ "\\\$grub_platform" = "efi" ]; then menuentry "Memtest86" { search --set=root --no-floppy --fs-uuid $uuid - chainloader /EFI/memtest86/memtest$ARCH.efi + chainloader $loader_filename } fi EOF @@ -94,53 +93,60 @@ FOE } _write_systemd_boot_cfg() { - systemdbootdir="$1" + local systemdbootdir="$1" + local loader_filename="$2" cat > "$systemdbootdir/memtest86-efi.conf" <<FOE title MemTest86 -efi /EFI/memtest86/memtest$ARCH.efi +efi $loader_filename FOE } install() { if [[ $install == 1 ]]; then - echo "MemTest86 is already installed in ESP. Nothing to do." > /dev/stderr + echo "MemTest86 is already installed in ESP. Nothing to do." >&2 exit $CODE_USAGE fi # Find ESP device number - partition=$(fdisk -l | grep "EFI System" | awk '{print $1}' | tail -n1) - if [[ -n "$partition" ]]; then - echo -en "Press Enter if ${CB}$partition${CR} is your ESP partition, " - echo -en "else enter device path manually (like ${CB}/dev/sdXY${CR}): " + esp_partition=$(fdisk -l | grep "EFI System" | awk '{print $1}' | tail -n1) + if [[ -n "$esp_partition" ]]; then + echo -en "Press Enter if ${CB}$esp_partition${CR} is your ESP partition, " + echo -en "else enter device path manually (like ${CB}/dev/sdXY${CR} or ${CB}/dev/nvme0nXpY${CR}): " else - echo -en "Enter device path for your ESP partition (like ${CB}/dev/sdXY${CR}): " + echo -en "Enter device path for your ESP partition (like ${CB}/dev/sdXY${CR} or ${CB}/dev/nvme0nXpY${CR}): " fi - partition=$(promptuser "$partition") - if [[ ! -b "$partition" ]]; then - echo -e "${CE}'$partition' is not a block device. Aborted.${CR}" > /dev/stderr + esp_partition=$(promptuser "$esp_partition") + if [[ ! -b "$esp_partition" ]]; then + echo -e "${CE}'$esp_partition' is not a block device. Aborted.${CR}" >&2 exit $CODE_VALUE fi - partnumber=$(echo "$partition" | grep -Eo '[0-9]+$') - [[ $partition == "/dev/nvme"* ]] && device=$(echo "$partition" | cut -dp -f1) || device=${partition//$partnumber} + partnumber=$(echo "$esp_partition" | grep -Eo '[0-9]+$') + [[ $esp_partition == "/dev/nvme"* ]] && device=$(echo "$esp_partition" | cut -dp -f1) || device=${esp_partition//$partnumber} if [[ -z "$partnumber" ]] || [[ -z "$device" ]]; then - echo -e "${CE}Not able to find partition number for '$partition'. Aborted.${CR}" > /dev/stderr + echo -e "${CE}Not able to find partition number for '$esp_partition'. Aborted.${CR}" >&2 exit $CODE_VALUE fi # Find ESP mount point - esp=$(mount | grep "$partition" | awk '{print $3}' | tail -n1) - if [[ -n "$esp" ]]; then - echo -en "Press Enter if ${CB}$esp${CR} is your mount point for ESP partition, " + esp_mount_path=$(mount | grep "$esp_partition" | awk '{print $3}' | tail -n1) + if [[ -n "$esp_mount_path" ]]; then + echo -en "Press Enter if ${CB}$esp_mount_path${CR} is your mount point for ESP partition, " echo -en "else enter mount point manually (like ${CB}/boot/efi${CR}): " else echo -en "Enter the mount point for the ESP partition (like ${CB}/boot/efi${CR}): " fi - esp=$(promptuser "$esp") + esp_mount_path=$(promptuser "$esp_mount_path") + + # Prompt for destination directory + memtest86_esp_path="/EFI/memtest86" + echo -en "Press Enter if ${CB}$memtest86_esp_path${CR} is the directory where you want to install MemTest86, " + echo -en "else enter something else (like ${CB}/EFI/tools/memtest86${CR}): " + memtest86_esp_path=$(promptuser "$memtest86_esp_path") # Check if ESP is mounted or mount it otherwise - _mount_esp "$partition" "$esp" - echo -e "The target is: ${CB}$partition${CR} (mounted on ${CB}$esp${CR}).\n" + _mount_esp "$esp_partition" "$esp_mount_path" + echo -e "The target is: ${CB}$esp_partition${CR} (mounted on ${CB}$esp_mount_path${CR}).\n" # Get user choice echo "Select $PRGNAME action to perform:" @@ -156,39 +162,53 @@ install() { 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" + 1) # Install MemTest86 in $esp_mount_path/ + memtest86_esp_bin="shell$ARCH.efi" + memtest86_esp_path="/" + [[ -f "$esp_mount_path/$memtest86_esp_bin" ]] && mv -v "$esp_mount_path/$memtest86_esp_bin" "$esp_mount_path/$memtest86_esp_bin.bak" # Backup if exist + _common_install "$esp_mount_path" "$memtest86_esp_bin" ;; - 2) # Install MemTest86 in $esp/EFI/memtest86/ & add an EFI boot entry + 2) # Install MemTest86 in ${esp_mount_path}${memtest86_esp_path}/ & add an EFI boot entry + memtest86_esp_bin="memtest$ARCH.efi" + # shellcheck disable=SC1003 + loader_filename="$(echo "$memtest86_esp_path/$memtest86_esp_bin" | tr '/' '\\')" checkcommand efibootmgr - _common_install "$esp/EFI/memtest86" "memtest$ARCH.efi" + _common_install "${esp_mount_path}${memtest86_esp_path}" "$memtest86_esp_bin" 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 + efibootmgr --create-only \ + --write-signature \ + --disk "$device" \ + --part "$partnumber" \ + --label "MemTest86" \ + --loader "$loader_filename" ;; - 3) # Install MemTest86 in $esp/EFI/memtest86/ & add a file for GRUB2 + 3) # Install MemTest86 in ${esp_mount_path}${memtest86_esp_path}/ & add a file for GRUB2 + memtest86_esp_bin="memtest$ARCH.efi" + loader_filename="$memtest86_esp_path/$memtest86_esp_bin" checkcommand grub-mkconfig if [[ ! -d "/etc/grub.d/" ]]; then - echo -e "${CE}GRUB2 seems not installed on your system. Aborted.${CR}" > /dev/stderr + echo -e "${CE}GRUB2 seems not installed on your system. Aborted.${CR}" >&2 exit $CODE_CMD fi - _common_install "$esp/EFI/memtest86" "memtest$ARCH.efi" + _common_install "${esp_mount_path}${memtest86_esp_path}" "$memtest86_esp_bin" echo -e "\nAdd a new configuration file for GRUB..." - uuid=$(blkid "$partition" -s UUID -o value) - _write_grub_cfg "$uuid" + uuid=$(blkid "$esp_partition" -s UUID -o value) + _write_grub_cfg "$uuid" "$loader_filename" grub-mkconfig -o "/boot/grub/grub.cfg" ;; - 4) # Install MemTest86 in $esp/EFI/memtest86/ & add a file for systemd-boot + 4) # Install MemTest86 in ${esp_mount_path}${memtest86_esp_path}/ & add a file for systemd-boot + memtest86_esp_bin="memtest$ARCH.efi" + loader_filename="$memtest86_esp_path/$memtest86_esp_bin" checkcommand bootctl - _common_install "$esp/EFI/memtest86" "memtest$ARCH.efi" + _common_install "${esp_mount_path}${memtest86_esp_path}" "$memtest86_esp_bin" echo -e "\nAdd a new configuration file for systemd-boot..." - systemdbootdir="$esp/loader/entries" + systemdbootdir="$esp_mount_path/loader/entries" mkdir -pv "$systemdbootdir" - _write_systemd_boot_cfg "$systemdbootdir" - bootctl --path="$esp" update + _write_systemd_boot_cfg "$systemdbootdir" "$loader_filename" + bootctl --path="$esp_mount_path" update ;; *) # Do nothing and quit @@ -198,30 +218,32 @@ install() { 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" + sed -i "s|@ESP_PARTITION@|$esp_partition|" "$CONFFILE" + sed -i "s|@ESP_MOUNT_PATH@|$esp_mount_path|" "$CONFFILE" + sed -i "s|@MEMTEST86_ESP_PATH@|$memtest86_esp_path|" "$CONFFILE" + sed -i "s|@MEMTEST86_ESP_BIN@|$memtest86_esp_bin|" "$CONFFILE" + sed -i "s|@CHOICE@|$choice|" "$CONFFILE" + sed -i "s|install=0|install=1|" "$CONFFILE" echo "MemTest86 has been installed in ESP." } update() { if [[ $install == 0 ]]; then - echo "MemTest86 is not installed in ESP: it cannot be updated." > /dev/stderr - exit $CODE_USAGE + echo "MemTest86 is not installed in ESP: no update to do." >&2 + exit $CODE_OK fi # Check if ESP is mounted or mount it otherwise - _mount_esp "$partition" "$esp" + _mount_esp "$esp_partition" "$esp_mount_path" case $choice in - 1) # Update files in $esp/ - _common_install "$esp" "shell$ARCH.efi" + 1) # Update files in $esp_mount_path/ + _common_install "$esp_mount_path" "$memtest86_esp_bin" ;; - 2|3|4) # Update files in $esp/EFI/memtest86/ - _common_install "$esp/EFI/memtest86" "memtest$ARCH.efi" + 2|3|4) # Update files in ${esp_mount_path}${memtest86_esp_path}/ + _common_install "${esp_mount_path}${memtest86_esp_path}" "$memtest86_esp_bin" ;; esac @@ -230,56 +252,61 @@ update() { remove() { if [[ $install == 0 ]]; then - echo "MemTest86 is not installed in ESP: it cannot be removed." > /dev/stderr - exit $CODE_USAGE + echo "MemTest86 is not installed in ESP: no deletion to do." >&2 + exit $CODE_OK fi # Check if ESP is mounted or mount it otherwise - _mount_esp "$partition" "$esp" + _mount_esp "$esp_partition" "$esp_mount_path" 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" + 1) # Remove files in $esp_mount_path/ + echo -e "MemTest86 will be removed from ${CB}$esp_mount_path/${CR}." + rm -v "$esp_mount_path/$memtest86_esp_bin" "$esp_mount_path/blacklist.cfg" "$esp_mount_path/mt86.png" "$esp_mount_path/unifont.bin" + [[ -f "$esp_mount_path/$memtest86_esp_bin.bak" ]] && mv -v "$esp_mount_path/$memtest86_esp_bin.bak" "$esp_mount_path/$memtest86_esp_bin" ;; - 2) # Remove files in $esp/EFI/memtest86/ & delete EFI boot entry + 2) # Remove files in ${esp_mount_path}${memtest86_esp_path}/ & 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 "MemTest86 will be removed from ${CB}${esp_mount_path}${memtest86_esp_path}/${CR}." + rm -rfv "${esp_mount_path:?}${memtest86_esp_path:?}" 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 + 3) # Remove files in ${esp_mount_path}${memtest86_esp_path}/ & 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 "MemTest86 will be removed from ${CB}${esp_mount_path}${memtest86_esp_path}/${CR}." + rm -rfv "${esp_mount_path:?}${memtest86_esp_path:?}" 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/" + 4) # Remove files in ${esp_mount_path}${memtest86_esp_path}/ & delete file for systemd-boot + checkcommand bootctl + + echo -e "MemTest86 will be removed from ${CB}${esp_mount_path}${memtest86_esp_path}/${CR}." + rm -rfv "${esp_mount_path:?}${memtest86_esp_path:?}" echo -e "\nRemove configuration file for systemd-boot..." - rm -v "$esp/loader/entries/memtest86-efi.conf" + rm -v "$esp_mount_path/loader/entries/memtest86-efi.conf" + bootctl --path="$esp_mount_path" update ;; 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" + sed -i "s|$esp_partition|@ESP_PARTITION@|" "$CONFFILE" + sed -i "s|$esp_mount_path|@ESP_MOUNT_PATH@|" "$CONFFILE" + sed -i "s|$memtest86_esp_path|@MEMTEST86_ESP_PATH@|" "$CONFFILE" + sed -i "s|$memtest86_esp_bin|@MEMTEST86_ESP_BIN@|" "$CONFFILE" + sed -i "s|$choice|@CHOICE@|" "$CONFFILE" + sed -i "s|install=1|install=0|" "$CONFFILE" echo "MemTest86 has been removed from ESP." } @@ -294,8 +321,10 @@ status() { exit $CODE_USAGE 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 "ESP device name: $esp_partition" + echo -e "ESP mount point: $esp_mount_path" + echo -e "MemTest86 installation directory (in ESP): $memtest86_esp_path" + echo -e "MemTest86 binary name (in ESP): $memtest86_esp_bin" echo -e "Type of installation: $choice" exit $CODE_OK fi @@ -317,10 +346,12 @@ about() { 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 $CODE_FATAL -fi +case "$(uname -m)" in + i686) ARCH="ia32";; + x86_64) ARCH="x64";; + aarch64) ARCH="aa64";; + *) echo -e "${CE} Unsupported ARCH: $(uname -m). Aborted.${CR}" >&2 ; exit $CODE_FATAL;; +esac case "$1" in -i|--install) warn; checkuid; install; exit $CODE_OK;; diff --git a/memtest86-efi-remove.hook b/memtest86-efi-remove.hook deleted file mode 100644 index e0288276ecd0..000000000000 --- a/memtest86-efi-remove.hook +++ /dev/null @@ -1,9 +0,0 @@ -[Trigger] -Operation = Remove -Type = File -Target = usr/share/memtest86-efi/*.efi - -[Action] -Description = Removing MemTest86 EFI from ESP -When = PostTransaction -Exec = /usr/bin/memtest86-efi --remove diff --git a/memtest86-efi.conf b/memtest86-efi.conf index bbb4a1022b2b..88f0cec22f86 100644 --- a/memtest86-efi.conf +++ b/memtest86-efi.conf @@ -1,9 +1,11 @@ # -# /etc/memtest86-efi.conf +# /etc/memtest86-efi/memtest86-efi.conf # MEMTEST86_PATH=/usr/share/memtest86-efi -partition=@PARTITION@ -esp=@ESP@ +esp_partition=@ESP_PARTITION@ +esp_mount_path=@ESP_MOUNT_PATH@ +memtest86_esp_path=@MEMTEST86_ESP_PATH@ +memtest86_esp_bin=@MEMTEST86_ESP_BIN@ choice=@CHOICE@ install=0 diff --git a/memtest86-efi.install b/memtest86-efi.install index 591fe358f21a..61600b7698ec 100644 --- a/memtest86-efi.install +++ b/memtest86-efi.install @@ -1,3 +1,57 @@ post_install() { echo -e "You can use command \033[4mmemtest86-efi --install\033[0m as root to install MemTest86 in your ESP." } + +pre_upgrade() { + if [[ $(vercmp "$2" "1:9.4build1000-4") -lt 0 ]]; then + rm /usr/share/libalpm/hooks/memtest86-efi-remove.hook + echo "Updating /etc/memtest86-efi/memtest86-efi.conf..." + echo -e "\033[4mCurrent file:\033[0m" + grep -v '^\s*$\|^\s*\#' /etc/memtest86-efi/memtest86-efi.conf + + source /etc/memtest86-efi/memtest86-efi.conf + if [[ $install == 0 ]]; then + cat > /etc/memtest86-efi/memtest86-efi.conf <<EOF +# +# /etc/memtest86-efi/memtest86-efi.conf +# + +MEMTEST86_PATH=/usr/share/memtest86-efi +esp_partition=@ESP_PARTITION@ +esp_mount_path=@ESP_MOUNT_PATH@ +memtest86_esp_path=@MEMTEST86_ESP_PATH@ +memtest86_esp_bin=@MEMTEST86_ESP_BIN@ +choice=@CHOICE@ +install=0 +EOF + else + sed -i "s/^partition=/esp_partition=/" "/etc/memtest86-efi/memtest86-efi.conf" + sed -i "s/^esp=/esp_mount_path=/" "/etc/memtest86-efi/memtest86-efi.conf" + case "$(uname -m)" in + i686) ARCH="ia32";; + x86_64) ARCH="x64";; + aarch64) ARCH="aa64";; + esac + case $choice in + 1) + memtest86_esp_path="/" + memtest86_esp_bin="shell$ARCH.efi" + ;; + + 2|3|4) + memtest86_esp_path="/EFI/memtest86" + memtest86_esp_bin="memtest$ARCH.efi" + ;; + esac + sed -i "/^esp_mount_path=.*/a memtest86_esp_path=$memtest86_esp_path" /etc/memtest86-efi/memtest86-efi.conf + sed -i "/^memtest86_esp_path=.*/a memtest86_esp_bin=$memtest86_esp_bin" /etc/memtest86-efi/memtest86-efi.conf + fi + + echo -e "\033[4mNew file:\033[0m" + grep -v '^\s*$\|^\s*\#' /etc/memtest86-efi/memtest86-efi.conf + fi +} + +pre_remove() { + /usr/bin/memtest86-efi --remove +} |