thias / glim

GRUB Live ISO Multiboot
638 stars 141 forks source link

Sorted menu #105

Closed slowpeek closed 1 year ago

slowpeek commented 1 year ago

Currently GLIM propagates menu items in the order or some wildcard expansion like debian/debian-live-*.iso. It is not what most users would like. Here I introduce sorting by iso mtime DESC first, iso filename literal value ASC next.

Main commit message:

Support functions for sorted menu feature

In generic shells the wildcard expansion produces an alphabetically ASC
sorted list. In grubscript there is no sorting, the items are generated in
so called "directory order" ('ls -U'), as they appear in the fs. Here we
introduce sorting based on file mtime DESC first, literal filename ASC
next.

In a typical scenario when a user puts a newly released iso into some dir
the new iso would naturally pop to the top in the dir's menu. In case there
is some iso in multiple flavours for the same version, a user should touch
those with the same mtime for the group to be sorted alphabetically.

When storing isos not sequentially it is a good idea to touch them with
their release date or mtime of some file from inside the iso like the
kernel or initrd.

Points of interest in grub sources:
- grub-core/commands/wildcard.c: wildcard_expand -> match_files -> fs->fs_dir
- grub-core/fs/fat.c: grub_fat_dir -> grub_fat_iterate_dir_next

Two other commits modify the inc-*.cfg files to use the feature. The changes are trivial. The big commit can be reviewed as-is. For the smaller one use 'ignore leading whitespace' setting in your client to grasp the actual changes quick.

Before:

Ubuntu 20.04.5 amd64 desktop
Ubuntu 22.04.2 amd64 desktop
Ubuntu 16.04.7 amd64 desktop
Ubuntu 18.04.6 amd64 desktop

After:

Ubuntu 22.04.2 amd64 desktop
Ubuntu 20.04.5 amd64 desktop
Ubuntu 18.04.6 amd64 desktop
Ubuntu 16.04.7 amd64 desktop
thias commented 1 year ago

I had already noticed this limitation many times, but never took the time to properly look into it. What you've done blows my mind, and it's thorough, clean, detailed.... I honestly can't find anything else to say than "Thank you!". It took me a while to grasp the logic from the shifting and setparams'ing, not to mention the limitations you found, worked around and documented! :exploding_head: Awesome contribution!!!