Blame SOURCES/0050-grubby-add-set-index-to-specify-which-position-to-ad.patch

16aa69
From ddf482232a47f5d2db9b3d40d89ee4094a6ac936 Mon Sep 17 00:00:00 2001
16aa69
From: Peter Jones <pjones@redhat.com>
16aa69
Date: Wed, 22 Jun 2016 14:07:49 -0400
16aa69
Subject: [PATCH 50/55] grubby: add --set-index to specify which position to
16aa69
 add new entries as
16aa69
16aa69
This adds an option, "--set-index N", to grubby, and will cause creation
16aa69
of any new entry to be at a particular zero-indexed position in the
16aa69
resulting configuration file.
16aa69
16aa69
Related: rhbz#1285601
16aa69
16aa69
Signed-off-by: Peter Jones <pjones@redhat.com>
16aa69
---
16aa69
 .gitignore             |  1 +
16aa69
 grubby.8               | 10 +++++++---
16aa69
 grubby.c               | 26 +++++++++++++++++++++-----
16aa69
 test.sh                | 14 ++++++++++++++
16aa69
 test/grub.15           | 19 +++++++++++++++++++
16aa69
 test/results/add/g1.10 | 22 ++++++++++++++++++++++
16aa69
 test/results/add/g1.17 | 19 +++++++++++++++++++
16aa69
 test/results/add/g1.8  | 22 ++++++++++++++++++++++
16aa69
 test/results/add/g1.9  | 22 ++++++++++++++++++++++
16aa69
 9 files changed, 147 insertions(+), 8 deletions(-)
16aa69
 create mode 100644 test/grub.15
16aa69
 create mode 100644 test/results/add/g1.10
16aa69
 create mode 100644 test/results/add/g1.17
16aa69
 create mode 100644 test/results/add/g1.8
16aa69
 create mode 100644 test/results/add/g1.9
16aa69
16aa69
diff --git a/.gitignore b/.gitignore
16aa69
index e78a392..1c00ff7 100644
16aa69
--- a/.gitignore
16aa69
+++ b/.gitignore
16aa69
@@ -3,3 +3,4 @@ version.h
16aa69
 *.o
16aa69
 core.*
16aa69
 vgcore.*
16aa69
+*.tar.*
16aa69
diff --git a/grubby.8 b/grubby.8
16aa69
index 85e22c5..b2a5447 100644
16aa69
--- a/grubby.8
16aa69
+++ b/grubby.8
16aa69
@@ -8,10 +8,10 @@ grubby \- command line tool for configuring grub, lilo, elilo, yaboot and zipl
16aa69
        [--bootloader-probe] [--config-file \fIpath\fR] [--copy-default]
16aa69
        [--debug] [--default-kernel] [--default-index] [--default-title]
16aa69
        [--grub] [--lilo] [--yaboot] [--silo] [--zipl]
16aa69
-       [--info=\fIkernel-path\fR] [--initrd=\fIinitrd-path\fR] 
16aa69
-       [--make-default] [-o path] [--version]
16aa69
+       [--info=\fIkernel-path\fR] [--initrd=\fIinitrd-path\fR]
16aa69
+       [--make-default] [-o path] [--version] [--set-entry=\fIentry-index\fR]
16aa69
        [--remove-kernel=\fIkernel-path\fR] [--remove-args=\fIargs\fR]
16aa69
-       [--set-default=\fIkernel-path\fR] [--set-default-index=\fientry-index\fR]
16aa69
+       [--set-default=\fIkernel-path\fR] [--set-default-index=\fIentry-index\fR]
16aa69
        [--title=entry-title] [--add-multiboot=\fImultiboot-path\fR]
16aa69
        [--mbargs=\fIargs\fR] [--remove-multiboot=\fImultiboot-path\fR]
16aa69
        [--remove-mbargs=\fIargs\fR]
16aa69
@@ -48,6 +48,10 @@ with that title are used.
16aa69
 Add a new boot entry for the kernel located at \fIkernel-path\fR.
16aa69
 
16aa69
 .TP
16aa69
+\fB-\-set-entry\fR=\fIentry-index\fR
16aa69
+Set the position at which to add a new entry created with \fB-\-add-kernel\fR.
16aa69
+
16aa69
+.TP
16aa69
 \fB-\-args\fR=\fIkernel-args\fR
16aa69
 When a new kernel is added, this specifies the command line arguments
16aa69
 which should be passed to the kernel by default (note they are merged
16aa69
diff --git a/grubby.c b/grubby.c
16aa69
index ad2b662..0c260f2 100644
16aa69
--- a/grubby.c
16aa69
+++ b/grubby.c
16aa69
@@ -4286,9 +4286,10 @@ int addNewKernel(struct grubConfig *config, struct singleEntry *template,
16aa69
 		 const char *newKernelPath, const char *newKernelTitle,
16aa69
 		 const char *newKernelArgs, const char *newKernelInitrd,
16aa69
 		 const char **extraInitrds, int extraInitrdCount,
16aa69
-		 const char *newMBKernel, const char *newMBKernelArgs)
16aa69
+		 const char *newMBKernel, const char *newMBKernelArgs
16aa69
+		 int newIndex)
16aa69
 {
16aa69
-	struct singleEntry *new;
16aa69
+	struct singleEntry *new, *entry, *prev = NULL;
16aa69
 	struct singleLine *newLine = NULL, *tmplLine = NULL, *masterLine = NULL;
16aa69
 	int needs;
16aa69
 	char *chptr;
16aa69
@@ -4318,9 +4319,20 @@ int addNewKernel(struct grubConfig *config, struct singleEntry *template,
16aa69
 	new = malloc(sizeof(*new));
16aa69
 	new->skip = 0;
16aa69
 	new->multiboot = 0;
16aa69
-	new->next = config->entries;
16aa69
 	new->lines = NULL;
16aa69
-	config->entries = new;
16aa69
+	entry = config->entries;
16aa69
+	for (unsigned int i = 0; i < newIndex; i++) {
16aa69
+		if (!entry)
16aa69
+			break;
16aa69
+		prev = entry;
16aa69
+		entry = entry->next;
16aa69
+	}
16aa69
+	new->next = entry;
16aa69
+
16aa69
+	if (prev)
16aa69
+		prev->next = new;
16aa69
+	else
16aa69
+		config->entries = new;
16aa69
 
16aa69
 	/* copy/update from the template */
16aa69
 	needs = NEED_KERNEL | NEED_TITLE;
16aa69
@@ -4771,6 +4783,7 @@ int main(int argc, const char **argv)
16aa69
 	char *newKernelVersion = NULL;
16aa69
 	char *newMBKernel = NULL;
16aa69
 	char *newMBKernelArgs = NULL;
16aa69
+	int newIndex = 0;
16aa69
 	char *removeMBKernelArgs = NULL;
16aa69
 	char *removeMBKernel = NULL;
16aa69
 	char *bootPrefix = NULL;
16aa69
@@ -4873,6 +4886,9 @@ int main(int argc, const char **argv)
16aa69
 		{"set-default-index", 0, POPT_ARG_INT, &defaultIndex, 0,
16aa69
 		 _("make the given entry index the default entry"),
16aa69
 		 _("entry-index")},
16aa69
+		{"set-index", 0, POPT_ARG_INT, &newIndex, 0,
16aa69
+		 _("use the given index when creating a new entry"),
16aa69
+		 _("entry-index")},
16aa69
 		{"silo", 0, POPT_ARG_NONE, &configureSilo, 0,
16aa69
 		 _("configure silo bootloader")},
16aa69
 		{"title", 0, POPT_ARG_STRING, &newKernelTitle, 0,
16aa69
@@ -5289,7 +5305,7 @@ int main(int argc, const char **argv)
16aa69
 	if (addNewKernel(config, template, bootPrefix, newKernelPath,
16aa69
 			 newKernelTitle, newKernelArgs, newKernelInitrd,
16aa69
 			 (const char **)extraInitrds, extraInitrdCount,
16aa69
-			 newMBKernel, newMBKernelArgs))
16aa69
+			 newMBKernel, newMBKernelArgs, newIndex))
16aa69
 		return 1;
16aa69
 
16aa69
 	if (numEntries(config) == 0) {
16aa69
diff --git a/test.sh b/test.sh
16aa69
index b90798c..9ac0ec9 100755
16aa69
--- a/test.sh
16aa69
+++ b/test.sh
16aa69
@@ -485,6 +485,20 @@ grubTest grub.8 add/g8.2 --add-kernel=/boot/new-kernel.img --title='title' \
16aa69
 grubTest grub.11 add/g11.1 --add-kernel=/boot/new-kernel.img --title='title' \
16aa69
     --initrd=/boot/new-initrd --boot-filesystem=/boot --copy-default \
16aa69
     --args='console=tty0 console=ttyS1,9600n81 single'
16aa69
+grubTest grub.1 add/g1.1 --add-kernel=/boot/new-kernel.img --title='title' \
16aa69
+    --initrd=/boot/new-initrd --boot-filesystem=/ --set-index 0
16aa69
+grubTest grub.1 add/g1.17 --add-kernel=/boot/new-kernel.img --title='title' \
16aa69
+    --initrd=/boot/new-initrd --boot-filesystem=/ --set-index 1
16aa69
+grubTest grub.1 add/g1.17 --add-kernel=/boot/new-kernel.img --title='title' \
16aa69
+    --initrd=/boot/new-initrd --boot-filesystem=/ --set-index 2
16aa69
+grubTest grub.15 add/g1.10 --add-kernel=/boot/new-kernel.img --title='title' \
16aa69
+    --initrd=/boot/new-initrd --boot-filesystem=/ --set-index 0
16aa69
+grubTest grub.15 add/g1.8 --add-kernel=/boot/new-kernel.img --title='title' \
16aa69
+    --initrd=/boot/new-initrd --boot-filesystem=/ --set-index 1
16aa69
+grubTest grub.15 add/g1.9 --add-kernel=/boot/new-kernel.img --title='title' \
16aa69
+    --initrd=/boot/new-initrd --boot-filesystem=/ --set-index 2
16aa69
+grubTest grub.15 add/g1.9 --add-kernel=/boot/new-kernel.img --title='title' \
16aa69
+    --initrd=/boot/new-initrd --boot-filesystem=/ --set-index 5
16aa69
 
16aa69
 testgrub2=n
16aa69
 ARCH=$(uname -m | sed s,i[3456789]86,ia32,)
16aa69
diff --git a/test/grub.15 b/test/grub.15
16aa69
new file mode 100644
16aa69
index 0000000..e1c5f8a
16aa69
--- /dev/null
16aa69
+++ b/test/grub.15
16aa69
@@ -0,0 +1,19 @@
16aa69
+# grub.conf generated by anaconda
16aa69
+#
16aa69
+# Note that you do not have to rerun grub after making changes to this file
16aa69
+# NOTICE:  You have a /boot partition.  This means that
16aa69
+#          all kernel and initrd paths are relative to /boot/, eg.
16aa69
+#          root (hd0,0)
16aa69
+#          kernel /vmlinuz-version ro root=/dev/sda1
16aa69
+#          initrd /initrd-version.img
16aa69
+#boot=/dev/hda
16aa69
+default=1
16aa69
+timeout=10
16aa69
+splashimage=(hd0,0)/grub/splash.xpm.gz
16aa69
+title Red Hat Linux (2.4.7-2)
16aa69
+	root (hd0,0)
16aa69
+	kernel /vmlinuz-2.4.7-2 ro root=/dev/sda1
16aa69
+	initrd /initrd-2.4.7-2.img
16aa69
+title zonk
16aa69
+	kernel /boot/new-kernel.img
16aa69
+	initrd /boot/new-initrd
16aa69
diff --git a/test/results/add/g1.10 b/test/results/add/g1.10
16aa69
new file mode 100644
16aa69
index 0000000..dcdd8a8
16aa69
--- /dev/null
16aa69
+++ b/test/results/add/g1.10
16aa69
@@ -0,0 +1,22 @@
16aa69
+# grub.conf generated by anaconda
16aa69
+#
16aa69
+# Note that you do not have to rerun grub after making changes to this file
16aa69
+# NOTICE:  You have a /boot partition.  This means that
16aa69
+#          all kernel and initrd paths are relative to /boot/, eg.
16aa69
+#          root (hd0,0)
16aa69
+#          kernel /vmlinuz-version ro root=/dev/sda1
16aa69
+#          initrd /initrd-version.img
16aa69
+#boot=/dev/hda
16aa69
+default=2
16aa69
+timeout=10
16aa69
+splashimage=(hd0,0)/grub/splash.xpm.gz
16aa69
+title title
16aa69
+	kernel /boot/new-kernel.img
16aa69
+	initrd /boot/new-initrd
16aa69
+title Red Hat Linux (2.4.7-2)
16aa69
+	root (hd0,0)
16aa69
+	kernel /vmlinuz-2.4.7-2 ro root=/dev/sda1
16aa69
+	initrd /initrd-2.4.7-2.img
16aa69
+title zonk
16aa69
+	kernel /boot/new-kernel.img
16aa69
+	initrd /boot/new-initrd
16aa69
diff --git a/test/results/add/g1.17 b/test/results/add/g1.17
16aa69
new file mode 100644
16aa69
index 0000000..6a38822
16aa69
--- /dev/null
16aa69
+++ b/test/results/add/g1.17
16aa69
@@ -0,0 +1,19 @@
16aa69
+# grub.conf generated by anaconda
16aa69
+#
16aa69
+# Note that you do not have to rerun grub after making changes to this file
16aa69
+# NOTICE:  You have a /boot partition.  This means that
16aa69
+#          all kernel and initrd paths are relative to /boot/, eg.
16aa69
+#          root (hd0,0)
16aa69
+#          kernel /vmlinuz-version ro root=/dev/sda1
16aa69
+#          initrd /initrd-version.img
16aa69
+#boot=/dev/hda
16aa69
+default=1
16aa69
+timeout=10
16aa69
+splashimage=(hd0,0)/grub/splash.xpm.gz
16aa69
+title Red Hat Linux (2.4.7-2)
16aa69
+	root (hd0,0)
16aa69
+	kernel /vmlinuz-2.4.7-2 ro root=/dev/sda1
16aa69
+	initrd /initrd-2.4.7-2.img
16aa69
+title title
16aa69
+	kernel /boot/new-kernel.img
16aa69
+	initrd /boot/new-initrd
16aa69
diff --git a/test/results/add/g1.8 b/test/results/add/g1.8
16aa69
new file mode 100644
16aa69
index 0000000..5893a2f
16aa69
--- /dev/null
16aa69
+++ b/test/results/add/g1.8
16aa69
@@ -0,0 +1,22 @@
16aa69
+# grub.conf generated by anaconda
16aa69
+#
16aa69
+# Note that you do not have to rerun grub after making changes to this file
16aa69
+# NOTICE:  You have a /boot partition.  This means that
16aa69
+#          all kernel and initrd paths are relative to /boot/, eg.
16aa69
+#          root (hd0,0)
16aa69
+#          kernel /vmlinuz-version ro root=/dev/sda1
16aa69
+#          initrd /initrd-version.img
16aa69
+#boot=/dev/hda
16aa69
+default=2
16aa69
+timeout=10
16aa69
+splashimage=(hd0,0)/grub/splash.xpm.gz
16aa69
+title Red Hat Linux (2.4.7-2)
16aa69
+	root (hd0,0)
16aa69
+	kernel /vmlinuz-2.4.7-2 ro root=/dev/sda1
16aa69
+	initrd /initrd-2.4.7-2.img
16aa69
+title title
16aa69
+	kernel /boot/new-kernel.img
16aa69
+	initrd /boot/new-initrd
16aa69
+title zonk
16aa69
+	kernel /boot/new-kernel.img
16aa69
+	initrd /boot/new-initrd
16aa69
diff --git a/test/results/add/g1.9 b/test/results/add/g1.9
16aa69
new file mode 100644
16aa69
index 0000000..310623d
16aa69
--- /dev/null
16aa69
+++ b/test/results/add/g1.9
16aa69
@@ -0,0 +1,22 @@
16aa69
+# grub.conf generated by anaconda
16aa69
+#
16aa69
+# Note that you do not have to rerun grub after making changes to this file
16aa69
+# NOTICE:  You have a /boot partition.  This means that
16aa69
+#          all kernel and initrd paths are relative to /boot/, eg.
16aa69
+#          root (hd0,0)
16aa69
+#          kernel /vmlinuz-version ro root=/dev/sda1
16aa69
+#          initrd /initrd-version.img
16aa69
+#boot=/dev/hda
16aa69
+default=2
16aa69
+timeout=10
16aa69
+splashimage=(hd0,0)/grub/splash.xpm.gz
16aa69
+title Red Hat Linux (2.4.7-2)
16aa69
+	root (hd0,0)
16aa69
+	kernel /vmlinuz-2.4.7-2 ro root=/dev/sda1
16aa69
+	initrd /initrd-2.4.7-2.img
16aa69
+title zonk
16aa69
+	kernel /boot/new-kernel.img
16aa69
+	initrd /boot/new-initrd
16aa69
+title title
16aa69
+	kernel /boot/new-kernel.img
16aa69
+	initrd /boot/new-initrd
16aa69
-- 
16aa69
2.5.5
16aa69