7e98da0
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
7e98da0
From: Peter Jones <pjones@redhat.com>
7e98da0
Date: Tue, 11 Sep 2018 14:20:37 -0400
7e98da0
Subject: [PATCH] Add a "version" command.
7e98da0
7e98da0
This adds a command that shows you info about grub's version, the grub target
7e98da0
platform, the compiler version, and if you built with
7e98da0
--with-rpm-version=<string>, the rpm package version.
7e98da0
7e98da0
Signed-off-by: Peter Jones <pjones@redhat.com>
7e98da0
---
7e98da0
 configure.ac                 | 13 ++++++++++
7e98da0
 grub-core/Makefile.core.def  |  5 ++++
7e98da0
 grub-core/commands/version.c | 56 ++++++++++++++++++++++++++++++++++++++++++++
7e98da0
 config.h.in                  |  1 +
7e98da0
 4 files changed, 75 insertions(+)
7e98da0
 create mode 100644 grub-core/commands/version.c
7e98da0
7e98da0
diff --git a/configure.ac b/configure.ac
7e98da0
index 9323c125469..61c4683cb76 100644
7e98da0
--- a/configure.ac
7e98da0
+++ b/configure.ac
7e98da0
@@ -287,6 +287,19 @@ AC_SUBST(target_cpu)
7e98da0
 AC_SUBST(platform)
7e98da0
 
7e98da0
 # Define default variables
7e98da0
+have_with_rpm_version=n
7e98da0
+AC_ARG_WITH([rpm_version],
7e98da0
+	    AS_HELP_STRING([--with-rpm-version=VERSION],
7e98da0
+			   [set the rpm package version [[guessed]]]),
7e98da0
+	    [have_with_rpm_version=y],
7e98da0
+	    [have_with_rpm_version=n])
7e98da0
+if test x$have_with_rpm_version = xy; then
7e98da0
+  rpm_version="$with_rpm_version"
7e98da0
+else
7e98da0
+  rpm_version=""
7e98da0
+fi
7e98da0
+GRUB_RPM_VERSION="$rpm_version"
7e98da0
+AC_SUBST(GRUB_RPM_VERSION)
7e98da0
 
7e98da0
 have_with_bootdir=n
7e98da0
 AC_ARG_WITH([bootdir],
7e98da0
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
7e98da0
index 144734e39e1..59ead422028 100644
7e98da0
--- a/grub-core/Makefile.core.def
7e98da0
+++ b/grub-core/Makefile.core.def
7e98da0
@@ -535,6 +535,11 @@ image = {
7e98da0
   enable = mips_loongson;
7e98da0
 };
7e98da0
 
7e98da0
+module = {
7e98da0
+  name = version;
7e98da0
+  common = commands/version.c;
7e98da0
+};
7e98da0
+
7e98da0
 module = {
7e98da0
   name = disk;
7e98da0
   common = lib/disk.c;
7e98da0
diff --git a/grub-core/commands/version.c b/grub-core/commands/version.c
7e98da0
new file mode 100644
7e98da0
index 00000000000..f0966a518f7
7e98da0
--- /dev/null
7e98da0
+++ b/grub-core/commands/version.c
7e98da0
@@ -0,0 +1,56 @@
7e98da0
+/* version.c - Command to print the grub version and build info. */
7e98da0
+/*
7e98da0
+ *  GRUB  --  GRand Unified Bootloader
7e98da0
+ *  Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
7e98da0
+ *
7e98da0
+ *  GRUB is free software: you can redistribute it and/or modify
7e98da0
+ *  it under the terms of the GNU General Public License as published by
7e98da0
+ *  the Free Software Foundation, either version 3 of the License, or
7e98da0
+ *  (at your option) any later version.
7e98da0
+ *
7e98da0
+ *  GRUB is distributed in the hope that it will be useful,
7e98da0
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
7e98da0
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7e98da0
+ *  GNU General Public License for more details.
7e98da0
+ *
7e98da0
+ *  You should have received a copy of the GNU General Public License
7e98da0
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
7e98da0
+ */
7e98da0
+
7e98da0
+#include <grub/dl.h>
7e98da0
+#include <grub/term.h>
7e98da0
+#include <grub/time.h>
7e98da0
+#include <grub/types.h>
7e98da0
+#include <grub/misc.h>
7e98da0
+#include <grub/extcmd.h>
7e98da0
+#include <grub/i18n.h>
7e98da0
+
7e98da0
+GRUB_MOD_LICENSE ("GPLv3+");
7e98da0
+
7e98da0
+static grub_err_t
7e98da0
+grub_cmd_version (grub_command_t cmd UNUSED, int argc, char **args UNUSED)
7e98da0
+{
7e98da0
+  if (argc != 0)
7e98da0
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("no arguments expected"));
7e98da0
+
7e98da0
+  grub_printf (_("GNU GRUB  version %s\n"), PACKAGE_VERSION);
7e98da0
+  grub_printf (_("Platform %s-%s\n"), GRUB_TARGET_CPU, GRUB_PLATFORM);
7e98da0
+  if (grub_strlen(GRUB_RPM_VERSION) != 0)
7e98da0
+    grub_printf (_("RPM package version %s\n"), GRUB_RPM_VERSION);
7e98da0
+  grub_printf (_("Compiler version %s\n"), __VERSION__);
7e98da0
+
7e98da0
+  return 0;
7e98da0
+}
7e98da0
+
7e98da0
+static grub_command_t cmd;
7e98da0
+
7e98da0
+GRUB_MOD_INIT(version)
7e98da0
+{
7e98da0
+  cmd = grub_register_command ("version", grub_cmd_version, NULL,
7e98da0
+			       N_("Print version and build information."));
7e98da0
+}
7e98da0
+
7e98da0
+GRUB_MOD_FINI(version)
7e98da0
+{
7e98da0
+  grub_unregister_command (cmd);
7e98da0
+}
7e98da0
diff --git a/config.h.in b/config.h.in
7e98da0
index 9e8f9911b18..c7e316f0f1f 100644
7e98da0
--- a/config.h.in
7e98da0
+++ b/config.h.in
7e98da0
@@ -59,6 +59,7 @@
7e98da0
 
7e98da0
 #define GRUB_TARGET_CPU "@GRUB_TARGET_CPU@"
7e98da0
 #define GRUB_PLATFORM "@GRUB_PLATFORM@"
7e98da0
+#define GRUB_RPM_VERSION "@GRUB_RPM_VERSION@"
7e98da0
 
7e98da0
 #define RE_ENABLE_I18N 1
7e98da0