Skip to content

Instantly share code, notes, and snippets.

@marinelli
Last active August 10, 2023 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marinelli/3795a93f833d394cb18a9edff53dd780 to your computer and use it in GitHub Desktop.
Save marinelli/3795a93f833d394cb18a9edff53dd780 to your computer and use it in GitHub Desktop.
--- 10_linux_zfs 2023-07-28 15:34:32.000000000 +0200
+++ 10_linux_zfs_grub_2.12~rc1 2023-08-01 10:08:36.802829248 +0200
@@ -30,8 +30,6 @@
export TEXTDOMAIN=grub
export TEXTDOMAINDIR="${datarootdir}/locale"
-set -u
-
## Skip early if zfs utils isn't installed (instead of failing on first zpool list)
if ! `which zfs >/dev/null 2>&1`; then
exit 0
@@ -420,18 +418,15 @@
initrd_list=""
kernel_list=""
candidate_kernel_list="$(find "${boot_dir}" -maxdepth 1 -type f -regex '.*/\(vmlinuz\|vmlinux\|kernel\)-.*')"
- while [ -n "${candidate_kernel_list}" ] ; do
- list_basename="$(echo "${candidate_kernel_list}" | sed -e 's#.*/##')"
- linux=$(version_find_latest ${list_basename})
- linux=$(echo "${candidate_kernel_list}" | while read k; do
- if [ "$(basename "${k}")" = "${linux}" ]; then
- echo -n "${k}"
- break
- fi
- done)
- # || true to not abort even if candidate_kernel_list is empty on last entry
- candidate_kernel_list="$(echo "${candidate_kernel_list}" | fgrep -vx "${linux}"||true)"
+ # Perform a reverse version sort on the entire list.
+ # Temporarily replace the '.old' suffix by ' 1' and append ' 2' for all
+ # other files to order the '.old' files after their non-old counterpart
+ # in reverse-sorted order.
+
+ reverse_sorted_list=$(echo $candidate_kernel_list | tr ' ' '\n' | sed -e 's/\.old$/ 1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$//')
+
+ for linux in ${reverse_sorted_list}; do
if ! grub_file_is_not_garbage "${linux}" ; then
continue
fi
@marinelli
Copy link
Author

marinelli commented Aug 1, 2023

Required due to the definition of version_sort, and the removal of version_find_latest [1].

[1] https://git.savannah.gnu.org/cgit/grub.git/commit/?id=a79c567f6b5820a8795c273a9eaabd06a1f92b29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment