Bug 1003433 - RFE: feature, Add an function or cmd to compare distro or pkg version
Summary: RFE: feature, Add an function or cmd to compare distro or pkg version
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: beakerlib
Version: 19
Hardware: All
OS: Linux
medium
unspecified
Target Milestone: ---
Assignee: Dalibor Pospíšil
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: Fedora-beakerlib-1.10 1136362
TreeView+ depends on / blocked
 
Reported: 2013-09-02 02:50 UTC by JianHong Yin
Modified: 2014-12-12 14:51 UTC (History)
2 users (show)

Fixed In Version: beakerlib-1.10-1
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-12-12 14:48:00 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description JianHong Yin 2013-09-02 02:50:12 UTC
Description of problem:
In many cases, we need compare distro or pkg version to judge 
 -if run the test case in the platform.
so want beakerlib, add an function or cmd to compare distro or pkg version

Version-Release number of selected component (if applicable):
all beakerlib version

How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:
here is an alternative complete I created: (based sort -V)
# cat /usr/local/bin/vercmp
# author jiyin
usage() {
        echo "usage: $0  <ver1> < =  | '>' | '<' | '>=' | '<=' >  <ver2>" >&2
        echo "       $0  <ver1> < eq | gt  | lt  |  ge  |  le  >  <ver2>" >&2
        echo "       $0  <ver1> < match >  <'pattern'>" >&2
}

vercmp() {
        [ $# != 3 ] && {
                usage
                return 1
        }
        vl=$1
        cmpType=$2
        vr=$3
        res=1

        [ "$vl" = "$vr" ] && eq=1
        vmax=$(echo -e "$vl\n$vr" | sort -V | tail -n 1)

        case "$cmpType" in
        =|eq) [ "$eq" = 1 ] && res=0;;
        \>|gt) [ "$eq" != 1 -a "$vl" = "$vmax" ] && res=0;;
        \<|lt) [ "$eq" != 1 -a "$vr" = "$vmax" ] && res=0;;
        \>=|lt) [ "$vl" = "$vmax" ] && res=0;;
        \<=|lt) [ "$vr" = "$vmax" ] && res=0;;
        *) echo "$vl" | egrep -q "$vr"; res=$?;;
        esac

        return $res
}
vercmp "$@"



Additional info:

Comment 1 Petr Muller 2013-10-01 09:40:06 UTC
Seems useful

Comment 2 JianHong Yin 2013-11-12 07:49:43 UTC
because in RHEL5 sort not support -V option;
update the code:

#!/bin/bash
#author: jiyin

usage() {
        echo "usage: $0  <ver1> < =  | '>' | '<' | '>=' | '<=' >  <ver2>" >&2
        echo "       $0  <ver1> < eq | gt  | lt  |  ge  |  le  >  <ver2>" >&2
        echo "       $0  <ver1> < match >  <'pattern'>" >&2
}

sortV() {
        if echo | sort -V 2>/dev/null; then
                cat - | sort -V
        else
                cat - | sed -r -e "s/-([0-9]+\.)/.\1/" -e "s/-([0-9]+\.)/-.\1/" |
                        sort -t . -k1,1 -k2,2n -k3,3n -k4,4n -k5,5n -k6,6n |
                        sed -r -e "s/\./-/" -e "s/-\./-/"
        fi
}
vercmp() {
        [ $# != 3 ] && {
                usage
                return 1
        }
        vl=$1
        cmpType=$2
        vr=$3
        res=1

        [ "$vl" = "$vr" ] && eq=1
        vmax=$(echo -e "$vl\n$vr" | sortV | tail -n 1)

        case "$cmpType" in
        =|eq) [ "$eq" = 1 ] && res=0;;
        \>|gt) [ "$eq" != 1 -a "$vl" = "$vmax" ] && res=0;;
        \<|lt) [ "$eq" != 1 -a "$vr" = "$vmax" ] && res=0;;
        \>=|lt) [ "$vl" = "$vmax" ] && res=0;;
        \<=|lt) [ "$vr" = "$vmax" ] && res=0;;
        *) echo "$vl" | egrep -q "$vr"; res=$?;;
        esac

        return $res
}
vercmp "$@"

Comment 3 Fedora Admin XMLRPC Client 2014-09-02 12:14:18 UTC
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.

Comment 4 Dalibor Pospíšil 2014-09-02 15:42:00 UTC
currently __INTERNAL_version_cmp and __INTERNAL_test_version aree present in beakerlib. I can make them publick in next release.


Note You need to log in before you can comment on or make changes to this bug.