Blame SOURCES/0253-BLS-files-should-only-be-copied-by-grub-switch-to-bl.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Javier Martinez Canillas <javierm@redhat.com>
d9d99f
Date: Tue, 4 Dec 2018 10:48:45 +0100
d9d99f
Subject: [PATCH] BLS files should only be copied by grub-switch-to-blscfg if
d9d99f
 BLS isn't set
d9d99f
d9d99f
Currently the grub-switch-to-blscfg script doesn't update the grub.cfg if
d9d99f
GRUB_ENABLE_BLSCFG=true is already set in /etc/default/grub. But it still
d9d99f
copies the BLS files which may overwrite fields modified by the user.
d9d99f
d9d99f
Related: rhbz#1638117
d9d99f
d9d99f
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
d9d99f
---
d9d99f
 util/grub-switch-to-blscfg.in | 80 +++++++++++++++++++++++--------------------
d9d99f
 1 file changed, 42 insertions(+), 38 deletions(-)
d9d99f
d9d99f
diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in
d9d99f
index d353370cc51..eeea1307706 100644
d9d99f
--- a/util/grub-switch-to-blscfg.in
d9d99f
+++ b/util/grub-switch-to-blscfg.in
d9d99f
@@ -220,49 +220,51 @@ EOF
d9d99f
     ) | cat
d9d99f
 }
d9d99f
 
d9d99f
-for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do
d9d99f
-    bls_target="${blsdir}/${MACHINE_ID}-${kernelver}.conf"
d9d99f
-    linux="/vmlinuz-${kernelver}"
d9d99f
-    linux_path="/boot${linux}"
d9d99f
-    kernel_dir="/lib/modules/${kernelver}"
d9d99f
+copy_bls() {
d9d99f
+    for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do
d9d99f
+	bls_target="${blsdir}/${MACHINE_ID}-${kernelver}.conf"
d9d99f
+	linux="/vmlinuz-${kernelver}"
d9d99f
+	linux_path="/boot${linux}"
d9d99f
+	kernel_dir="/lib/modules/${kernelver}"
d9d99f
 
d9d99f
-    if [ ! -d "${kernel_dir}" ] ; then
d9d99f
-        continue
d9d99f
-    fi
d9d99f
-    if [ ! -f "${linux_path}" ]; then
d9d99f
-        continue
d9d99f
-    fi
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_path}")"
d9d99f
-    bootprefix="${linux_relpath%%"${linux}"}"
d9d99f
+	linux_relpath="$("${grub_mkrelpath}" "${linux_path}")"
d9d99f
+	bootprefix="${linux_relpath%%"${linux}"}"
d9d99f
 
d9d99f
-    if [ -f "${kernel_dir}/bls.conf" ] ; then
d9d99f
-        cp -af "${kernel_dir}/bls.conf" "${bls_target}"
d9d99f
-        if [ -n "${bootprefix}" ]; then
d9d99f
-            sed -i -e "s,^\(linux[^ \t]*[ \t]\+\).*,\1${bootprefix}${linux},g" "${bls_target}"
d9d99f
-            sed -i -e "/^initrd/ s,\([ \t]\+\)\([^ \t]\+\),\1${bootprefix}\2,g" "${bls_target}"
d9d99f
-        fi
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
+	if [ -f "${kernel_dir}/bls.conf" ] ; then
d9d99f
+            cp -af "${kernel_dir}/bls.conf" "${bls_target}"
d9d99f
+            if [ -n "${bootprefix}" ]; then
d9d99f
+		sed -i -e "s,^\(linux[^ \t]*[ \t]\+\).*,\1${bootprefix}${linux},g" "${bls_target}"
d9d99f
+		sed -i -e "/^initrd/ s,\([ \t]\+\)\([^ \t]\+\),\1${bootprefix}\2,g" "${bls_target}"
d9d99f
+            fi
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
-    if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
d9d99f
-        bls_debug="$(echo ${bls_target} | sed -e "s/${kernelver}/${kernelver}~debug/")"
d9d99f
-        cp -aT  "${bls_target}" "${bls_debug}"
d9d99f
-        title="$(grep '^title[ \t]' "${bls_debug}" | sed -e 's/^title[ \t]*//')"
d9d99f
-        blsid="$(grep '^id[ \t]' "${bls_debug}" | sed -e "s/\.${ARCH}/-debug.${arch}/")"
d9d99f
-        sed -i -e "s/^title.*/title ${title}${GRUB_LINUX_DEBUG_TITLE_POSTFIX}/" "${bls_debug}"
d9d99f
-        sed -i -e "s/^id.*/${blsid}/" "${bls_debug}"
d9d99f
-        sed -i -e "s/^options.*/options \$kernelopts ${GRUB_CMDLINE_LINUX_DEBUG}/" "${bls_debug}"
d9d99f
-    fi
d9d99f
-done
d9d99f
+	if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
d9d99f
+            bls_debug="$(echo ${bls_target} | sed -e "s/${kernelver}/${kernelver}~debug/")"
d9d99f
+            cp -aT  "${bls_target}" "${bls_debug}"
d9d99f
+            title="$(grep '^title[ \t]' "${bls_debug}" | sed -e 's/^title[ \t]*//')"
d9d99f
+            blsid="$(grep '^id[ \t]' "${bls_debug}" | sed -e "s/\.${ARCH}/-debug.${arch}/")"
d9d99f
+            sed -i -e "s/^title.*/title ${title}${GRUB_LINUX_DEBUG_TITLE_POSTFIX}/" "${bls_debug}"
d9d99f
+            sed -i -e "s/^id.*/${blsid}/" "${bls_debug}"
d9d99f
+            sed -i -e "s/^options.*/options \$kernelopts ${GRUB_CMDLINE_LINUX_DEBUG}/" "${bls_debug}"
d9d99f
+	fi
d9d99f
+    done
d9d99f
 
d9d99f
-if [ -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
+    if [ -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
+}
d9d99f
 
d9d99f
 GENERATE=0
d9d99f
 if grep '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" \
d9d99f
@@ -283,6 +285,8 @@ elif ! grep -q '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" ; then
d9d99f
 fi
d9d99f
 
d9d99f
 if [ "${GENERATE}" -eq 1 ] ; then
d9d99f
+    copy_bls
d9d99f
+
d9d99f
     if [ $arch = "x86_64" ] && [ ! -d /sys/firmware/efi ]; then
d9d99f
 	if ! cp ${prefix}/lib/grub//i386-pc/blscfg.mod ${grubdir}/i386-pc/ ; then
d9d99f
 	    exit 1