grub2/SOURCES/0095-Add-a-version-command.patch

135 lines
4.0 KiB
Diff
Raw Normal View History

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