On Fri, 27 Sep 2013, Cristian Ionescu-Idbohrn wrote:
> On Fri, 27 Sep 2013, Ian Campbell wrote:
> >
> > This all seems like a lot of fuss to go through simply to allow this
> > stuff to run on a completely ancient (2.5 or earlier kernel).
> >
> > But if you must why not just use linux-version from the
> > linux-base-package?
> >         $ linux-version --help
> >         Usage: /usr/bin/linux-version compare VERSION1 OP VERSION2
> >                /usr/bin/linux-version sort [--reverse] [VERSION1 VERSION2 
> > ...]
> >                /usr/bin/linux-version list [--paths]
> >
> >         The version arguments should be kernel version strings as shown by
> >         'uname -r' and used in filenames.
> >
> >         The valid comparison operators are: lt le eq ge gt
>
> Yes.  That would be simplier, but it will create a dependency to
> package linux-base (Priority: optional).

This (more fuss ;) is a simplier and more robust example of kernel version
comparison function:

#!/bin/sh

set -eu
#set -x

cmp_1_le_2() {
        [ $# -eq 2 ] || {
                echo "cmp_1_le_2: wrong number of arguments" >&2
                exit 1
        }

        local IFS=.- _1 _2

        _1=$1
        _2=$2

        set -- $_1
        [ $# -ge 2 ] || {
                echo "cmp_1_le_2: bad 1:st version number '$_1'" >&2
                exit 1
        }
        local v1
        v1=$(($(($1 << 8)) + $2))

        set -- $_2
        [ $# -ge 2 ] || {
                echo "cmp_1_le_2: bad 2:nd version number '$_2'" >&2
                exit 1
        }
        local v2
        v2=$(($(($1 << 8)) + $2))

        [ $v1 -le $v2 ]
}

if cmp_1_le_2 $1 $2; then
        echo "$1 <= $2"
else
        echo "$1 > $2"
fi


Cheers,

-- 
Cristian


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to