nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone
5593c8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5593c8
From: Peter Jones <pjones@redhat.com>
5593c8
Date: Tue, 11 Sep 2018 14:20:37 -0400
5593c8
Subject: [PATCH] Add a "version" command.
5593c8
5593c8
This adds a command that shows you info about grub's version, the grub target
5593c8
platform, the compiler version, and if you built with
5593c8
--with-rpm-version=<string>, the rpm package version.
5593c8
5593c8
Signed-off-by: Peter Jones <pjones@redhat.com>
5593c8
---
5593c8
 configure.ac                 | 13 ++++++++++
5593c8
 grub-core/Makefile.core.def  |  5 ++++
5593c8
 grub-core/commands/version.c | 56 ++++++++++++++++++++++++++++++++++++++++++++
5593c8
 config.h.in                  |  1 +
5593c8
 4 files changed, 75 insertions(+)
5593c8
 create mode 100644 grub-core/commands/version.c
5593c8
5593c8
diff --git a/configure.ac b/configure.ac
d3c3ab
index 152e7dba652..cfdac6bed5a 100644
5593c8
--- a/configure.ac
5593c8
+++ b/configure.ac
5593c8
@@ -312,6 +312,19 @@ AC_SUBST(target_cpu)
5593c8
 AC_SUBST(platform)
5593c8
 
5593c8
 # Define default variables
5593c8
+have_with_rpm_version=n
5593c8
+AC_ARG_WITH([rpm_version],
5593c8
+	    AS_HELP_STRING([--with-rpm-version=VERSION],
5593c8
+			   [set the rpm package version [[guessed]]]),
5593c8
+	    [have_with_rpm_version=y],
5593c8
+	    [have_with_rpm_version=n])
5593c8
+if test x$have_with_rpm_version = xy; then
5593c8
+  rpm_version="$with_rpm_version"
5593c8
+else
5593c8
+  rpm_version=""
5593c8
+fi
5593c8
+GRUB_RPM_VERSION="$rpm_version"
5593c8
+AC_SUBST(GRUB_RPM_VERSION)
5593c8
 
5593c8
 have_with_bootdir=n
5593c8
 AC_ARG_WITH([bootdir],
5593c8
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
d3c3ab
index 84a3d89de9a..498ca11762a 100644
5593c8
--- a/grub-core/Makefile.core.def
5593c8
+++ b/grub-core/Makefile.core.def
5593c8
@@ -579,6 +579,11 @@ image = {
5593c8
   enable = mips_loongson;
5593c8
 };
5593c8
 
5593c8
+module = {
5593c8
+  name = version;
5593c8
+  common = commands/version.c;
5593c8
+};
5593c8
+
5593c8
 module = {
5593c8
   name = disk;
5593c8
   common = lib/disk.c;
5593c8
diff --git a/grub-core/commands/version.c b/grub-core/commands/version.c
5593c8
new file mode 100644
d3c3ab
index 00000000000..f0966a518f7
5593c8
--- /dev/null
5593c8
+++ b/grub-core/commands/version.c
5593c8
@@ -0,0 +1,56 @@
5593c8
+/* version.c - Command to print the grub version and build info. */
5593c8
+/*
5593c8
+ *  GRUB  --  GRand Unified Bootloader
5593c8
+ *  Copyright (C) 2006,2007,2008  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
+
5593c8
+#include <grub/dl.h>
5593c8
+#include <grub/term.h>
5593c8
+#include <grub/time.h>
5593c8
+#include <grub/types.h>
5593c8
+#include <grub/misc.h>
5593c8
+#include <grub/extcmd.h>
5593c8
+#include <grub/i18n.h>
5593c8
+
5593c8
+GRUB_MOD_LICENSE ("GPLv3+");
5593c8
+
5593c8
+static grub_err_t
5593c8
+grub_cmd_version (grub_command_t cmd UNUSED, int argc, char **args UNUSED)
5593c8
+{
5593c8
+  if (argc != 0)
5593c8
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("no arguments expected"));
5593c8
+
5593c8
+  grub_printf (_("GNU GRUB  version %s\n"), PACKAGE_VERSION);
5593c8
+  grub_printf (_("Platform %s-%s\n"), GRUB_TARGET_CPU, GRUB_PLATFORM);
5593c8
+  if (grub_strlen(GRUB_RPM_VERSION) != 0)
5593c8
+    grub_printf (_("RPM package version %s\n"), GRUB_RPM_VERSION);
5593c8
+  grub_printf (_("Compiler version %s\n"), __VERSION__);
5593c8
+
5593c8
+  return 0;
5593c8
+}
5593c8
+
5593c8
+static grub_command_t cmd;
5593c8
+
5593c8
+GRUB_MOD_INIT(version)
5593c8
+{
5593c8
+  cmd = grub_register_command ("version", grub_cmd_version, NULL,
5593c8
+			       N_("Print version and build information."));
5593c8
+}
5593c8
+
5593c8
+GRUB_MOD_FINI(version)
5593c8
+{
5593c8
+  grub_unregister_command (cmd);
5593c8
+}
5593c8
diff --git a/config.h.in b/config.h.in
d3c3ab
index 9e8f9911b18..c7e316f0f1f 100644
5593c8
--- a/config.h.in
5593c8
+++ b/config.h.in
5593c8
@@ -59,6 +59,7 @@
5593c8
 
5593c8
 #define GRUB_TARGET_CPU "@GRUB_TARGET_CPU@"
5593c8
 #define GRUB_PLATFORM "@GRUB_PLATFORM@"
5593c8
+#define GRUB_RPM_VERSION "@GRUB_RPM_VERSION@"
5593c8
 
5593c8
 #define RE_ENABLE_I18N 1
5593c8