Blame SOURCES/0159-grub-switch-to-blscfg.in-Better-boot-prefix-checking.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Peter Jones <pjones@redhat.com>
d9d99f
Date: Fri, 22 Jun 2018 14:04:28 -0400
d9d99f
Subject: [PATCH] grub-switch-to-blscfg.in: Better boot prefix checking
d9d99f
d9d99f
Signed-off-by: Peter Jones <pjones@redhat.com>
d9d99f
---
d9d99f
 util/grub-switch-to-blscfg.in | 36 +++++++++++++++++-------------------
d9d99f
 1 file changed, 17 insertions(+), 19 deletions(-)
d9d99f
d9d99f
diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in
b71686
index dac41e738..884cf45b1 100644
d9d99f
--- a/util/grub-switch-to-blscfg.in
d9d99f
+++ b/util/grub-switch-to-blscfg.in
d9d99f
@@ -219,30 +219,31 @@ EOF
d9d99f
 }
d9d99f
 
d9d99f
 for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do
d9d99f
-    if [ ! -d "/lib/modules/${kernelver}" ] ; then
d9d99f
-        continue
d9d99f
-    fi
d9d99f
-    if [ ! -f "/boot/vmlinuz-${kernelver}" ]; then
d9d99f
-        continue
d9d99f
-    fi
d9d99f
     bls_target="${blsdir}/${MACHINE_ID}-${kernelver}.conf"
d9d99f
+    linux="$(grep '^linux[ \t]' "${bls_target}" | sed -e 's,^linux[ \t]+,,')"
d9d99f
     kernel_dir="/lib/modules/${kernelver}"
d9d99f
-    if [ -f "${kernel_dir}/bls.conf" ]; then
d9d99f
+
d9d99f
+    if [ ! -d "${kernel_dir}" ] ; then
d9d99f
+        continue
d9d99f
+    fi
d9d99f
+    if [ ! -f "${linux_path}" ]; then
d9d99f
+        continue
d9d99f
+    fi
d9d99f
+
d9d99f
+    linux_relpath="$("${grub_mkrelpath}" "${linux}")"
d9d99f
+    bootprefix="${linux%%"${linux_relpath}"}"
d9d99f
+
d9d99f
+    if [ -f "${kernel_dir}/bls.conf" ] ; then
d9d99f
         cp -af "${kernel_dir}/bls.conf" "${bls_target}"
d9d99f
     else
d9d99f
         mkbls "${kernelver}" \
d9d99f
             "$(date -u +%Y%m%d%H%M%S -d "$(stat -c '%y' "${kernel_dir}")")" \
d9d99f
+            "${bootprefix}" \
d9d99f
             >"${bls_target}"
d9d99f
     fi
d9d99f
 
d9d99f
-    linux="$(grep '^linux[ \t]' "${bls_target}" | sed -e 's,^linux[ \t]*,,')"
d9d99f
-    initrd="$(grep '^initrd[ \t]' "${bls_target}" | sed -e 's,^initrd[ \t]*,,')"
d9d99f
-    linux_relpath="$("${grub_mkrelpath}" /boot/$linux)"
d9d99f
-    initrd_relpath="$("${grub_mkrelpath}" /boot/$initrd)"
d9d99f
-
d9d99f
-    if [ $linux != $linux_relpath ] ; then
d9d99f
-        sed -i -e "s,^linux.*,linux ${linux_relpath},g" "${bls_target}"
d9d99f
-        sed -i -e "s,^initrd.*,initrd ${initrd_relpath},g" "${bls_target}"
d9d99f
+    if [ -n "${bootprefix}" ]; then
d9d99f
+        sed -i -e "s,\([ \t]\)${bootprefix},\1,g" "${bls_target}"
d9d99f
     fi
d9d99f
 
d9d99f
     if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
d9d99f
@@ -257,10 +258,7 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do
d9d99f
     fi
d9d99f
 done
d9d99f
 
d9d99f
-if [ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then
d9d99f
-    if [ $linux != $linux_relpath ]; then
d9d99f
-        bootprefix="$(dirname ${linux_relpath})"
d9d99f
-    fi
d9d99f
+if [ -n "${bootprefix}" -a -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then
d9d99f
     mkbls "0-rescue-${MACHINE_ID}" "0" "${bootprefix}" >"${blsdir}/${MACHINE_ID}-0-rescue.conf"
d9d99f
 fi
d9d99f