Bug 1003433
| Summary: | RFE: feature, Add an function or cmd to compare distro or pkg version | ||
|---|---|---|---|
| Product: | [Fedora] Fedora | Reporter: | JianHong Yin <jiyin> |
| Component: | beakerlib | Assignee: | Dalibor Pospíšil <dapospis> |
| Status: | CLOSED CURRENTRELEASE | QA Contact: | Fedora Extras Quality Assurance <extras-qa> |
| Severity: | unspecified | Docs Contact: | |
| Priority: | medium | ||
| Version: | 19 | CC: | pmuller, psplicha |
| Target Milestone: | --- | Keywords: | Patch |
| Target Release: | --- | ||
| Hardware: | All | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | beakerlib-1.10-1 | Doc Type: | Bug Fix |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2014-12-12 14:48:00 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
| Bug Depends On: | |||
| Bug Blocks: | 1136360, 1136362 | ||
Seems useful 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 "$@"
This package has changed ownership in the Fedora Package Database. Reassigning to the new owner of this component. currently __INTERNAL_version_cmp and __INTERNAL_test_version aree present in beakerlib. I can make them publick in next release. |
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: