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

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