[clug] Sorting Version Numbers

jm jeffm at ghostgun.com
Tue Jan 9 04:26:14 UTC 2018


On 9/01/2018 11:04, Luke Mewburn wrote:
>   | Anyone have any thoughts on this?
>
> Like you probably did, I did some searching on the web
> and experimentation.
>
> Your email prompted me to look into this again,
> because I've had the same requirement...
>
> My findings, in most-useful to least-useful order :)
>
>
> 1. Use yum tools that already exist: package-cleanup
>
> I found
> 	package-cleanup --oldkernels --count=3
> (in yum-utils on CentOS 6/7) seemed to do the right thing.
> For one of my build systems where I have other kernel-devel packages
> that I want to keep, I instead used:
> 	package-cleanup --oldkernels --keepdevel --count=3
>
> See: https://www.centos.org/forums/viewtopic.php?t=2120

Didn't know this one about this one which I guess isĀ  I asked. From that
web page it seems adding installonly_limit=3 to /etc/yum.conf may remove
my need for this step all together though some of the reports also state
that it doesn't work.

It still seems I need to run,

grub2-mkconfig -o /boot/grub2/grub.cfg

which isn't a problem. I've used these two steps on a number of machines
today and it's been working fine.
>
> 2. Use sort -V. (not quite there).
>
> The "sort --version-compare" (AKA "sort -V") option in GNU
> coreutils sort (which is on el7) almost does the right thing,
> except that it doesn't list the "unpatched" kernel first.
>
> E.g., given your input
> 	kernel-2.6.32-642.11.1.el7.x86_64
> 	kernel-2.6.32-642.1.1.el7.x86_64
> 	kernel-2.6.32-573.22.1.el7.x86_64
> 	kernel-2.6.32-642.4.2.el7.x86_64
> 	kernel-2.6.32-642.13.1.el7.x86_64
> with the addition of
> 	kernel-2.6.32-642.el7.x86_64
> sort -V orders as
> 	kernel-2.6.32-573.22.1.el7.x86_64
> 	kernel-2.6.32-642.1.1.el7.x86_64
> 	kernel-2.6.32-642.4.2.el7.x86_64
> 	kernel-2.6.32-642.11.1.el7.x86_64
> 	kernel-2.6.32-642.13.1.el7.x86_64
> 	kernel-2.6.32-642.el7.x86_64
> where the last line should be the 2nd.
>
> See: https://serverfault.com/questions/601427/sort-installed-packages-version
Came across this after posting the email. Read the man page (
https://www.gnu.org/software/coreutils/manual/html_node/Details-about-version-sort.html
) and didn't realise that the caveats would bite me. My test case isn't
as complete as it should be. You've save me from potentially deleting a
needed kernel sometime in the future.

> 3. Implement your own python script importing rpmUtils (in yum)
>
> Requires a bunch of mucking about with the guts of rpmUtils.
> Probably not worth it.
>
> See: http://blog.jasonantman.com/2014/07/how-yum-and-rpm-compare-versions/
>
Yeah, I'm trying to avoid that at all cost. It just introduces yet more
stuff I have to maintain.

Base on what you've told me number 1 is the the way to go.

Jeff.



More information about the linux mailing list