[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH 4/5] Add new '--default-index' feature.



This displays the (numeric) index of the default entry directly
from the parsed configuration file.

Signed-off-by: Cleber Rosa <crosa redhat com>
---
 grubby.8                    |    8 ++++++--
 grubby.c                    |   12 ++++++++++--
 test.sh                     |   17 +++++++++++++++++
 test/results/defaultindex/0 |    1 +
 test/results/defaultindex/2 |    1 +
 5 files changed, 35 insertions(+), 4 deletions(-)
 create mode 100644 test/results/defaultindex/0
 create mode 100644 test/results/defaultindex/2

diff --git a/grubby.8 b/grubby.8
index aaa061b..ca2c93f 100644
--- a/grubby.8
+++ b/grubby.8
@@ -5,8 +5,8 @@ grubby \- command line tool for configuring grub, lilo, and elilo
 .SH SYNOPSIS
 \fBgrubby\fR [--add-kernel=\fIkernel-path\fR] [--args=\fIargs\fR] 
        [--bad-image-okay] [--boot-filesystem=\fIbootfs\fR] 
-       [--bootloader-probe] [--config-file \fIpath\fR] 
-       [--copy-default] [--default-kernel] 
+       [--bootloader-probe] [--config-file \fIpath\fR] [--copy-default]
+       [--default-kernel] [--default-index]
        [--grub] [--lilo] [--yaboot] [--silo] [--zipl]
        [--info=\fIkernel-path\fR] [--initrd=\fIinitrd-path\fR] 
        [--make-default] [-o path] [--version]
@@ -98,6 +98,10 @@ and initrd path will never be copied.
 Display the full path to the current default kernel and exit.
 
 .TP
+\fB-\-default-index\fR
+Display the numeric index of the current default boot entry and exit.
+
+.TP
 \fB-\-elilo\fR
 Use an \fBelilo\fR style configuration file.
 
diff --git a/grubby.c b/grubby.c
index 7c98978..0158c2e 100644
--- a/grubby.c
+++ b/grubby.c
@@ -3159,6 +3159,7 @@ int main(int argc, const char ** argv) {
     struct singleEntry * template = NULL;
     int copyDefault = 0, makeDefault = 0;
     int displayDefault = 0;
+    int displayDefaultIndex = 0;
     struct poptOption options[] = {
 	{ "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0,
 	    _("add an entry for the specified kernel"), _("kernel-path") },
@@ -3191,6 +3192,8 @@ int main(int argc, const char ** argv) {
 	      "template"), NULL },
 	{ "default-kernel", 0, 0, &displayDefault, 0,
 	    _("display the path of the default kernel") },
+	{ "default-index", 0, 0, &displayDefaultIndex, 0,
+	    _("display the index of the default kernel") },
 	{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,
 	    _("configure elilo bootloader") },
 	{ "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0,
@@ -3334,7 +3337,7 @@ int main(int argc, const char ** argv) {
 
     if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion ||
 			  newKernelPath || removeKernelPath || makeDefault ||
-			  defaultKernel)) {
+			  defaultKernel || displayDefaultIndex)) {
 	fprintf(stderr, _("grubby: --bootloader-probe may not be used with "
 			  "specified option"));
 	return 1;
@@ -3385,7 +3388,7 @@ int main(int argc, const char ** argv) {
 
     if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel
 	&& !kernelInfo && !bootloaderProbe && !updateKernelPath 
-        && !removeMBKernel) {
+        && !removeMBKernel && !displayDefaultIndex) {
 	fprintf(stderr, _("grubby: no action specified\n"));
 	return 1;
     }
@@ -3480,6 +3483,11 @@ int main(int argc, const char ** argv) {
                ((rootspec != NULL) ? strlen(rootspec) : 0));
 
 	return 0;
+
+    } else if (displayDefaultIndex) {
+        if (config->defaultImage == -1) return 0;
+        printf("%i\n", config->defaultImage);
+
     } else if (kernelInfo)
 	return displayInfo(config, kernelInfo, bootPrefix);
 
diff --git a/test.sh b/test.sh
index 95d552b..b1e467b 100755
--- a/test.sh
+++ b/test.sh
@@ -198,6 +198,19 @@ grubTest grub.4 default/g4.1 --boot-filesystem=/ --set-default=/boot/vmlinuz-2.4
 grubTest grub.4 default/g4.2 --boot-filesystem=/ --set-default=/boot/vmlinuz-2.4.7-ac3 --remove-kernel /boot/vmlinuz-2.4.7-2.5 --add-kernel=/boot/new-kernel --copy-default --title New_Title
 grubTest grub.6 default/g6.1 --remove-kernel=/boot/vmlinuz-2.4.7-2.9 --boot-filesystem=/
 
+testing="GRUB display default index"
+grubDisplayTest grub.1 defaultindex/0 --default-index
+grubDisplayTest grub.2 defaultindex/0 --default-index
+grubDisplayTest grub.3 defaultindex/0 --default-index
+grubDisplayTest grub.4 defaultindex/0 --default-index
+grubDisplayTest grub.5 defaultindex/0 --default-index
+grubDisplayTest grub.6 defaultindex/2 --default-index
+grubDisplayTest grub.7 defaultindex/2 --default-index
+grubDisplayTest grub.8 defaultindex/0 --default-index
+grubDisplayTest grub.9 defaultindex/0 --default-index
+grubDisplayTest grub.10 defaultindex/0 --default-index
+grubDisplayTest grub.10 defaultindex/0 --default-index
+
 testing="LILO default directive"
 liloTest lilo.1 default/l1.1 --set-default=/boot/vmlinuz-2.4.18-4
 liloTest lilo.1 default/l1.2 --remove-kernel=/boot/vmlinuz-2.4.18-4smp
@@ -342,6 +355,10 @@ testing="GRUB2 add initrd"
 grub2Test grub2.2 add/g2-1.4 --update-kernel=/boot/new-kernel.img \
     --initrd=/boot/new-initrd --boot-filesystem=/boot/
 
+testing="GRUB2 display default index"
+grub2DisplayTest grub2.1 defaultindex/0 --default-index
+grub2DisplayTest grub2.2 defaultindex/0 --default-index
+
 testing="YABOOT add kernel"
 yabootTest yaboot.1 add/y1.1 --copy-default --boot-filesystem=/ --add-kernel=/boot/new-kernel  \
     --title=newtitle
diff --git a/test/results/defaultindex/0 b/test/results/defaultindex/0
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/test/results/defaultindex/0
@@ -0,0 +1 @@
+0
diff --git a/test/results/defaultindex/2 b/test/results/defaultindex/2
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/test/results/defaultindex/2
@@ -0,0 +1 @@
+2
-- 
1.7.6.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]