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

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

 



This displays the title of the default entry directly from the
parsed configuration file.

Signed-off-by: Cleber Rosa <crosa@xxxxxxxxxx>
---
 grubby.8                       |    6 +++-
 grubby.c                       |   55 ++++++++++++++++++++++++++++++++++++++-
 test.sh                        |   17 ++++++++++++
 test/results/defaulttitle/g.1  |    1 +
 test/results/defaulttitle/g.10 |    1 +
 test/results/defaulttitle/g.11 |    1 +
 test/results/defaulttitle/g.2  |    1 +
 test/results/defaulttitle/g.3  |    1 +
 test/results/defaulttitle/g.4  |    1 +
 test/results/defaulttitle/g.5  |    1 +
 test/results/defaulttitle/g.6  |    1 +
 test/results/defaulttitle/g.7  |    1 +
 test/results/defaulttitle/g.8  |    1 +
 test/results/defaulttitle/g.9  |    1 +
 test/results/defaulttitle/g2.1 |    1 +
 test/results/defaulttitle/g2.2 |    1 +
 16 files changed, 88 insertions(+), 3 deletions(-)
 create mode 100644 test/results/defaulttitle/g.1
 create mode 100644 test/results/defaulttitle/g.10
 create mode 100644 test/results/defaulttitle/g.11
 create mode 100644 test/results/defaulttitle/g.2
 create mode 100644 test/results/defaulttitle/g.3
 create mode 100644 test/results/defaulttitle/g.4
 create mode 100644 test/results/defaulttitle/g.5
 create mode 100644 test/results/defaulttitle/g.6
 create mode 100644 test/results/defaulttitle/g.7
 create mode 100644 test/results/defaulttitle/g.8
 create mode 100644 test/results/defaulttitle/g.9
 create mode 100644 test/results/defaulttitle/g2.1
 create mode 100644 test/results/defaulttitle/g2.2

diff --git a/grubby.8 b/grubby.8
index ca2c93f..b6ed82e 100644
--- a/grubby.8
+++ b/grubby.8
@@ -6,7 +6,7 @@ grubby \- command line tool for configuring grub, lilo, and elilo
 \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] [--default-index]
+       [--default-kernel] [--default-index] [--default-title]
        [--grub] [--lilo] [--yaboot] [--silo] [--zipl]
        [--info=\fIkernel-path\fR] [--initrd=\fIinitrd-path\fR] 
        [--make-default] [-o path] [--version]
@@ -102,6 +102,10 @@ Display the full path to the current default kernel and exit.
 Display the numeric index of the current default boot entry and exit.
 
 .TP
+\fB-\-default-title\fR
+Display the title 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 0158c2e..987543a 100644
--- a/grubby.c
+++ b/grubby.c
@@ -3160,6 +3160,7 @@ int main(int argc, const char ** argv) {
     int copyDefault = 0, makeDefault = 0;
     int displayDefault = 0;
     int displayDefaultIndex = 0;
+    int displayDefaultTitle = 0;
     struct poptOption options[] = {
 	{ "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0,
 	    _("add an entry for the specified kernel"), _("kernel-path") },
@@ -3194,6 +3195,8 @@ int main(int argc, const char ** argv) {
 	    _("display the path of the default kernel") },
 	{ "default-index", 0, 0, &displayDefaultIndex, 0,
 	    _("display the index of the default kernel") },
+	{ "default-title", 0, 0, &displayDefaultTitle, 0,
+	    _("display the title of the default kernel") },
 	{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,
 	    _("configure elilo bootloader") },
 	{ "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0,
@@ -3337,7 +3340,7 @@ int main(int argc, const char ** argv) {
 
     if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion ||
 			  newKernelPath || removeKernelPath || makeDefault ||
-			  defaultKernel || displayDefaultIndex)) {
+			  defaultKernel || displayDefaultIndex || displayDefaultTitle)) {
 	fprintf(stderr, _("grubby: --bootloader-probe may not be used with "
 			  "specified option"));
 	return 1;
@@ -3388,7 +3391,7 @@ int main(int argc, const char ** argv) {
 
     if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel
 	&& !kernelInfo && !bootloaderProbe && !updateKernelPath 
-        && !removeMBKernel && !displayDefaultIndex) {
+        && !removeMBKernel && !displayDefaultIndex && !displayDefaultTitle) {
 	fprintf(stderr, _("grubby: no action specified\n"));
 	return 1;
     }
@@ -3484,6 +3487,54 @@ int main(int argc, const char ** argv) {
 
 	return 0;
 
+    } else if (displayDefaultTitle) {
+	struct singleLine * line;
+	struct singleEntry * entry;
+
+	if (config->defaultImage == -1) return 0;
+	entry = findEntryByIndex(config, config->defaultImage);
+	if (!entry) return 0;
+
+	if (!configureGrub2) {
+	  line = getLineByType(LT_TITLE, entry->lines);
+	  if (!line) return 0;
+	  printf("%s\n", line->elements[1].item);
+
+	} else {
+	  int i;
+	  size_t len;
+	  char * start;
+	  char * tmp;
+
+	  dbgPrintf("This is GRUB2, default title is embeded in menuentry\n");
+	  line = getLineByType(LT_MENUENTRY, entry->lines);
+	  if (!line) return 0;
+
+	  for (i = 0; i < line->numElements; i++) {
+
+	    if (!strcmp(line->elements[i].item, "menuentry"))
+	      continue;
+
+	    if (*line->elements[i].item == '\'')
+	      start = line->elements[i].item + 1;
+	    else
+	      start = line->elements[i].item;
+
+	    len = strlen(start);
+	    if (*(start + len - 1) == '\'') {
+	      tmp = strdup(start);
+	      *(tmp + len - 1) = '\0';
+	      printf("%s", tmp);
+	      free(tmp);
+	      break;
+	    } else {
+	      printf("%s ", start);
+	    }
+	  }
+	  printf("\n");
+	}
+	return 0;
+
     } else if (displayDefaultIndex) {
         if (config->defaultImage == -1) return 0;
         printf("%i\n", config->defaultImage);
diff --git a/test.sh b/test.sh
index b1e467b..2b91d3c 100755
--- a/test.sh
+++ b/test.sh
@@ -211,6 +211,19 @@ grubDisplayTest grub.9 defaultindex/0 --default-index
 grubDisplayTest grub.10 defaultindex/0 --default-index
 grubDisplayTest grub.10 defaultindex/0 --default-index
 
+testing="GRUB display default title"
+grubDisplayTest grub.1 defaulttitle/g.1 --default-title
+grubDisplayTest grub.2 defaulttitle/g.2 --default-title
+grubDisplayTest grub.3 defaulttitle/g.3 --default-title
+grubDisplayTest grub.4 defaulttitle/g.4 --default-title
+grubDisplayTest grub.5 defaulttitle/g.5 --default-title
+grubDisplayTest grub.6 defaulttitle/g.6 --default-title
+grubDisplayTest grub.7 defaulttitle/g.7 --default-title
+grubDisplayTest grub.8 defaulttitle/g.8 --default-title
+grubDisplayTest grub.9 defaulttitle/g.9 --default-title
+grubDisplayTest grub.10 defaulttitle/g.10 --default-title
+grubDisplayTest grub.11 defaulttitle/g.11 --default-title
+
 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
@@ -359,6 +372,10 @@ testing="GRUB2 display default index"
 grub2DisplayTest grub2.1 defaultindex/0 --default-index
 grub2DisplayTest grub2.2 defaultindex/0 --default-index
 
+testing="GRUB display default title"
+grub2DisplayTest grub2.1 defaulttitle/g2.1 --default-title
+grub2DisplayTest grub2.2 defaulttitle/g2.2 --default-title
+
 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/defaulttitle/g.1 b/test/results/defaulttitle/g.1
new file mode 100644
index 0000000..1ae63f2
--- /dev/null
+++ b/test/results/defaulttitle/g.1
@@ -0,0 +1 @@
+Red Hat Linux (2.4.7-2)
diff --git a/test/results/defaulttitle/g.10 b/test/results/defaulttitle/g.10
new file mode 100644
index 0000000..1be72f4
--- /dev/null
+++ b/test/results/defaulttitle/g.10
@@ -0,0 +1 @@
+xen
diff --git a/test/results/defaulttitle/g.11 b/test/results/defaulttitle/g.11
new file mode 100644
index 0000000..ed80cb1
--- /dev/null
+++ b/test/results/defaulttitle/g.11
@@ -0,0 +1 @@
+Red Hat Linux (2.4.7-2smp)
diff --git a/test/results/defaulttitle/g.2 b/test/results/defaulttitle/g.2
new file mode 100644
index 0000000..1ae63f2
--- /dev/null
+++ b/test/results/defaulttitle/g.2
@@ -0,0 +1 @@
+Red Hat Linux (2.4.7-2)
diff --git a/test/results/defaulttitle/g.3 b/test/results/defaulttitle/g.3
new file mode 100644
index 0000000..ed80cb1
--- /dev/null
+++ b/test/results/defaulttitle/g.3
@@ -0,0 +1 @@
+Red Hat Linux (2.4.7-2smp)
diff --git a/test/results/defaulttitle/g.4 b/test/results/defaulttitle/g.4
new file mode 100644
index 0000000..7efb93f
--- /dev/null
+++ b/test/results/defaulttitle/g.4
@@ -0,0 +1 @@
+Red Hat Linux (2.4.7-2.9)
diff --git a/test/results/defaulttitle/g.5 b/test/results/defaulttitle/g.5
new file mode 100644
index 0000000..5c69edc
--- /dev/null
+++ b/test/results/defaulttitle/g.5
@@ -0,0 +1 @@
+Red Hat Linux (2.4.7-2.5)
diff --git a/test/results/defaulttitle/g.6 b/test/results/defaulttitle/g.6
new file mode 100644
index 0000000..3a71c0a
--- /dev/null
+++ b/test/results/defaulttitle/g.6
@@ -0,0 +1 @@
+Red Hat Linux (2.4.7-ac3)
diff --git a/test/results/defaulttitle/g.7 b/test/results/defaulttitle/g.7
new file mode 100644
index 0000000..3a71c0a
--- /dev/null
+++ b/test/results/defaulttitle/g.7
@@ -0,0 +1 @@
+Red Hat Linux (2.4.7-ac3)
diff --git a/test/results/defaulttitle/g.8 b/test/results/defaulttitle/g.8
new file mode 100644
index 0000000..1ae63f2
--- /dev/null
+++ b/test/results/defaulttitle/g.8
@@ -0,0 +1 @@
+Red Hat Linux (2.4.7-2)
diff --git a/test/results/defaulttitle/g.9 b/test/results/defaulttitle/g.9
new file mode 100644
index 0000000..ed80cb1
--- /dev/null
+++ b/test/results/defaulttitle/g.9
@@ -0,0 +1 @@
+Red Hat Linux (2.4.7-2smp)
diff --git a/test/results/defaulttitle/g2.1 b/test/results/defaulttitle/g2.1
new file mode 100644
index 0000000..e72b5c9
--- /dev/null
+++ b/test/results/defaulttitle/g2.1
@@ -0,0 +1 @@
+Linux, with Linux 2.6.38.8-32.fc15.x86_64
diff --git a/test/results/defaulttitle/g2.2 b/test/results/defaulttitle/g2.2
new file mode 100644
index 0000000..787215d
--- /dev/null
+++ b/test/results/defaulttitle/g2.2
@@ -0,0 +1 @@
+title
-- 
1.7.6.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux