Bug 1003433 - RFE: feature, Add an function or cmd to compare distro or pkg version
RFE: feature, Add an function or cmd to compare distro or pkg version
Status: CLOSED CURRENTRELEASE
Product: Fedora
Classification: Fedora
Component: beakerlib (Show other bugs)
19
All Linux
medium Severity unspecified
: ---
: ---
Assigned To: Dalibor Pospíšil
Fedora Extras Quality Assurance
: Patch
Depends On:
Blocks: Fedora-beakerlib-1.10 1136362
  Show dependency treegraph
 
Reported: 2013-09-01 22:50 EDT by Yin.JianHong
Modified: 2014-12-12 09:51 EST (History)
2 users (show)

See Also:
Fixed In Version: beakerlib-1.10-1
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2014-12-12 09:48:00 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Yin.JianHong 2013-09-01 22:50:12 EDT
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@redhat.com
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 05:40:06 EDT
Seems useful
Comment 2 Yin.JianHong 2013-11-12 02:49:43 EST
because in RHEL5 sort not support -V option;
update the code:

#!/bin/bash
#author: jiyin@redhat.com

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 08:14:18 EDT
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 11:42:00 EDT
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.