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

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