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