Blame SOURCES/0051-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch

5593c8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5593c8
From: Peter Jones <pjones@redhat.com>
5593c8
Date: Thu, 23 Jun 2016 11:01:39 -0400
5593c8
Subject: [PATCH] Add grub-get-kernel-settings and use it in 10_linux
5593c8
5593c8
This patch adds grub-get-kernel-settings, which reads the system kernel
5593c8
installation configuration from /etc/sysconfig/kernel, and outputs
5593c8
${GRUB_...} variables suitable for evaluation by grub-mkconfig.  Those
5593c8
variables are then used by 10_linux to choose whether or not to create
5593c8
debug stanzas.
5593c8
5593c8
Resolves: rhbz#1226325
5593c8
---
5593c8
 configure.ac                                   |  2 +
5593c8
 Makefile.util.def                              |  7 ++
5593c8
 util/bash-completion.d/grub-completion.bash.in | 22 +++++++
5593c8
 util/grub-get-kernel-settings.3                | 20 ++++++
5593c8
 util/grub-get-kernel-settings.in               | 88 ++++++++++++++++++++++++++
5593c8
 util/grub-mkconfig.in                          |  3 +
5593c8
 util/grub.d/10_linux.in                        | 23 +++++--
5593c8
 7 files changed, 160 insertions(+), 5 deletions(-)
5593c8
 create mode 100644 util/grub-get-kernel-settings.3
5593c8
 create mode 100644 util/grub-get-kernel-settings.in
5593c8
5593c8
diff --git a/configure.ac b/configure.ac
1c6ba0
index 30fd84d806..ed31ea457d 100644
5593c8
--- a/configure.ac
5593c8
+++ b/configure.ac
5593c8
@@ -65,6 +65,7 @@ grub_TRANSFORM([grub-install])
5593c8
 grub_TRANSFORM([grub-mkconfig])
5593c8
 grub_TRANSFORM([grub-mkfont])
5593c8
 grub_TRANSFORM([grub-mkimage])
5593c8
+grub_TRANSFORM([grub-get-kernel-settings])
5593c8
 grub_TRANSFORM([grub-glue-efi])
5593c8
 grub_TRANSFORM([grub-mklayout])
5593c8
 grub_TRANSFORM([grub-mkpasswd-pbkdf2])
5593c8
@@ -82,6 +83,7 @@ grub_TRANSFORM([grub-file])
5593c8
 grub_TRANSFORM([grub-bios-setup.3])
5593c8
 grub_TRANSFORM([grub-editenv.1])
5593c8
 grub_TRANSFORM([grub-fstest.3])
5593c8
+grub_TRANSFORM([grub-get-kernel-settings.3])
5593c8
 grub_TRANSFORM([grub-glue-efi.3])
5593c8
 grub_TRANSFORM([grub-install.1])
5593c8
 grub_TRANSFORM([grub-kbdcomp.3])
5593c8
diff --git a/Makefile.util.def b/Makefile.util.def
1c6ba0
index 1a7dd433e3..cdd2f51fe4 100644
5593c8
--- a/Makefile.util.def
5593c8
+++ b/Makefile.util.def
5593c8
@@ -732,6 +732,13 @@ script = {
5593c8
   installdir = sbin;
5593c8
 };
5593c8
 
5593c8
+script = {
5593c8
+  name = grub-get-kernel-settings;
5593c8
+  common = util/grub-get-kernel-settings.in;
5593c8
+  mansection = 3;
5593c8
+  installdir = sbin;
5593c8
+};
5593c8
+
5593c8
 script = {
5593c8
   name = grub-set-default;
5593c8
   common = util/grub-set-default.in;
5593c8
diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in
1c6ba0
index 44bf135b9f..5c4acd496d 100644
5593c8
--- a/util/bash-completion.d/grub-completion.bash.in
5593c8
+++ b/util/bash-completion.d/grub-completion.bash.in
5593c8
@@ -264,6 +264,28 @@ have ${__grub_sparc64_setup_program} && \
5593c8
 unset __grub_sparc64_setup_program
5593c8
 
5593c8
 
5593c8
+#
5593c8
+# grub-get-kernel-settings
5593c8
+#
5593c8
+_grub_get_kernel_settings () {
5593c8
+    local cur
5593c8
+
5593c8
+    COMPREPLY=()
5593c8
+    cur=`_get_cword`
5593c8
+
5593c8
+    if [[ "$cur" == -* ]]; then
5593c8
+        __grubcomp "$(__grub_get_options_from_help)"
5593c8
+    else
5593c8
+        # Default complete with a filename
5593c8
+        _filedir
5593c8
+    fi
5593c8
+}
5593c8
+__grub_get_kernel_settings_program="@grub_get_kernel_settings@"
5593c8
+have ${__grub_get_kernel_settings_program} && \
5593c8
+ complete -F _grub_get_kernel_settings -o filenames ${__grub_get_kernel_settings_program}
5593c8
+unset __grub_get_kernel_settings_program
5593c8
+
5593c8
+
5593c8
 #
5593c8
 # grub-install
5593c8
 #
5593c8
diff --git a/util/grub-get-kernel-settings.3 b/util/grub-get-kernel-settings.3
5593c8
new file mode 100644
1c6ba0
index 0000000000..ba33330e28
5593c8
--- /dev/null
5593c8
+++ b/util/grub-get-kernel-settings.3
5593c8
@@ -0,0 +1,20 @@
5593c8
+.TH GRUB-GET-KERNEL-SETTINGS 3 "Thu Jun 25 2015"
5593c8
+.SH NAME
5593c8
+\fBgrub-get-kernel-settings\fR \(em Evaluate the system's kernel installation settings for use while making a grub configuration file.
5593c8
+
5593c8
+.SH SYNOPSIS
5593c8
+\fBgrub-get-kernel-settings\fR [OPTION]
5593c8
+
5593c8
+.SH DESCRIPTION
5593c8
+\fBgrub-get-kernel-settings\fR reads the kernel installation settings on the host system, and emits a set of grub settings suitable for use when creating a grub configuration file.
5593c8
+
5593c8
+.SH OPTIONS
5593c8
+.TP
5593c8
+-h, --help
5593c8
+Display program usage and exit.
5593c8
+.TP
5593c8
+-v, --version
5593c8
+Display the current version.
5593c8
+
5593c8
+.SH SEE ALSO
5593c8
+.BR "info grub"
5593c8
diff --git a/util/grub-get-kernel-settings.in b/util/grub-get-kernel-settings.in
5593c8
new file mode 100644
1c6ba0
index 0000000000..7e87dfccc0
5593c8
--- /dev/null
5593c8
+++ b/util/grub-get-kernel-settings.in
5593c8
@@ -0,0 +1,88 @@
5593c8
+#!/bin/sh
5593c8
+set -e
5593c8
+
5593c8
+# Evaluate new-kernel-pkg's configuration file.
5593c8
+# Copyright (C) 2016 Free Software Foundation, Inc.
5593c8
+#
5593c8
+# GRUB is free software: you can redistribute it and/or modify
5593c8
+# it under the terms of the GNU General Public License as published by
5593c8
+# the Free Software Foundation, either version 3 of the License, or
5593c8
+# (at your option) any later version.
5593c8
+#
5593c8
+# GRUB is distributed in the hope that it will be useful,
5593c8
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
5593c8
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5593c8
+# GNU General Public License for more details.
5593c8
+#
5593c8
+# You should have received a copy of the GNU General Public License
5593c8
+# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
5593c8
+
5593c8
+PACKAGE_NAME=@PACKAGE_NAME@
5593c8
+PACKAGE_VERSION=@PACKAGE_VERSION@
5593c8
+datadir="@datadir@"
5593c8
+if [ "x$pkgdatadir" = x ]; then
5593c8
+    pkgdatadir="${datadir}/@PACKAGE@"
5593c8
+fi
5593c8
+
5593c8
+self=`basename $0`
5593c8
+
5593c8
+export TEXTDOMAIN=@PACKAGE@
5593c8
+export TEXTDOMAINDIR="@localedir@"
5593c8
+
5593c8
+. "${pkgdatadir}/grub-mkconfig_lib"
5593c8
+
5593c8
+# Usage: usage
5593c8
+# Print the usage.
5593c8
+usage () {
5593c8
+    gettext_printf "Usage: %s [OPTION]\n" "$self"
5593c8
+    gettext "Evaluate new-kernel-pkg configuration"; echo
5593c8
+    echo
5593c8
+    print_option_help "-h, --help" "$(gettext "print this message and exit")"
5593c8
+    print_option_help "-v, --version" "$(gettext "print the version information and exit")"
5593c8
+    echo
5593c8
+}
5593c8
+
5593c8
+# Check the arguments.
5593c8
+while test $# -gt 0
5593c8
+do
5593c8
+    option=$1
5593c8
+    shift
5593c8
+
5593c8
+    case "$option" in
5593c8
+    -h | --help)
5593c8
+	usage
5593c8
+	exit 0 ;;
5593c8
+    -v | --version)
5593c8
+	echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
5593c8
+	exit 0 ;;
5593c8
+    -*)
5593c8
+	gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
5593c8
+	usage
5593c8
+	exit 1
5593c8
+	;;
5593c8
+    # Explicitly ignore non-option arguments, for compatibility.
5593c8
+    esac
5593c8
+done
5593c8
+
5593c8
+if test -f /etc/sysconfig/kernel ; then
5593c8
+    . /etc/sysconfig/kernel
5593c8
+fi
5593c8
+
5593c8
+if [ "$MAKEDEBUG" = "yes" ]; then
5593c8
+    echo GRUB_LINUX_MAKE_DEBUG=true
5593c8
+    echo export GRUB_LINUX_MAKE_DEBUG
5593c8
+    echo GRUB_CMDLINE_LINUX_DEBUG=\"systemd.log_level=debug systemd.log_target=kmsg\"
5593c8
+    echo export GRUB_CMDLINE_LINUX_DEBUG
5593c8
+    echo GRUB_LINUX_DEBUG_TITLE_POSTFIX=\" with debugging\"
5593c8
+    echo export GRUB_LINUX_DEBUG_TITLE_POSTFIX
5593c8
+fi
5593c8
+if [ "$DEFAULTDEBUG" = "yes" ]; then
5593c8
+    echo GRUB_DEFAULT_TO_DEBUG=true
5593c8
+else
5593c8
+    echo GRUB_DEFAULT_TO_DEBUG=false
5593c8
+fi
5593c8
+echo export GRUB_DEFAULT_TO_DEBUG
5593c8
+if [ "$UPDATEDEFAULT" = "yes" ]; then
5593c8
+    echo GRUB_UPDATE_DEFAULT_KERNEL=true
5593c8
+    echo export GRUB_UPDATE_DEFAULT_KERNEL
5593c8
+fi
5593c8
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
1c6ba0
index ba14cf6261..005f093809 100644
5593c8
--- a/util/grub-mkconfig.in
5593c8
+++ b/util/grub-mkconfig.in
5593c8
@@ -45,6 +45,7 @@ grub_probe="${sbindir}/@grub_probe@"
5593c8
 grub_file="${bindir}/@grub_file@"
5593c8
 grub_editenv="${bindir}/@grub_editenv@"
5593c8
 grub_script_check="${bindir}/@grub_script_check@"
5593c8
+grub_get_kernel_settings="${sbindir}/@grub_get_kernel_settings@"
5593c8
 
5593c8
 export TEXTDOMAIN=@PACKAGE@
5593c8
 export TEXTDOMAINDIR="@localedir@"
5593c8
@@ -158,6 +159,8 @@ if test -f ${sysconfdir}/default/grub ; then
5593c8
   . ${sysconfdir}/default/grub
5593c8
 fi
5593c8
 
5593c8
+eval "$("${grub_get_kernel_settings}")" || true
5593c8
+
5593c8
 if [ "x${GRUB_DISABLE_UUID}" = "xtrue" ]; then
5593c8
   if [ -z "${GRUB_DISABLE_LINUX_UUID}" ]; then
5593c8
     GRUB_DISABLE_LINUX_UUID="true"
5593c8
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
1c6ba0
index 2e59f3b419..0f3c19e30c 100644
5593c8
--- a/util/grub.d/10_linux.in
5593c8
+++ b/util/grub.d/10_linux.in
5593c8
@@ -111,7 +111,8 @@ linux_entry ()
5593c8
   os="$1"
5593c8
   version="$2"
5593c8
   type="$3"
5593c8
-  args="$4"
5593c8
+  isdebug="$4"
5593c8
+  args="$5"
5593c8
 
5593c8
   if [ -z "$boot_device_id" ]; then
5593c8
       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
5593c8
@@ -123,6 +124,9 @@ linux_entry ()
5593c8
 	  quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
5593c8
 	  title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
5593c8
       fi
5593c8
+      if [ x$isdebug = xdebug ]; then
5593c8
+	  title="$title${GRUB_LINUX_DEBUG_TITLE_POSTFIX}"
5593c8
+      fi
5593c8
       echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
5593c8
   else
5593c8
       echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
5593c8
@@ -299,11 +303,15 @@ while [ "x$list" != "x" ] ; do
5593c8
   fi
5593c8
 
5593c8
   if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
5593c8
-    linux_entry "${OS}" "${version}" simple \
5593c8
+    linux_entry "${OS}" "${version}" simple standard \
5593c8
     "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
5593c8
+    if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
5593c8
+      linux_entry "${OS}" "${version}" simple debug \
5593c8
+        "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
5593c8
+    fi
5593c8
 
5593c8
     submenu_indentation="$grub_tab"
5593c8
-    
5593c8
+
5593c8
     if [ -z "$boot_device_id" ]; then
5593c8
 	boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
5593c8
     fi
5593c8
@@ -312,10 +320,15 @@ while [ "x$list" != "x" ] ; do
5593c8
     is_top_level=false
5593c8
   fi
5593c8
 
5593c8
-  linux_entry "${OS}" "${version}" advanced \
5593c8
+  linux_entry "${OS}" "${version}" advanced standard \
5593c8
               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
5593c8
+  if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
5593c8
+    linux_entry "${OS}" "${version}" advanced debug \
5593c8
+                "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
5593c8
+  fi
5593c8
+
5593c8
   if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
5593c8
-    linux_entry "${OS}" "${version}" recovery \
5593c8
+    linux_entry "${OS}" "${version}" recovery standard \
5593c8
                 "single ${GRUB_CMDLINE_LINUX}"
5593c8
   fi
5593c8