rpmvercmp (was: dovecot imap available for testing, latest upstream release 0.99.10.6)

Alexandre Oliva aoliva at redhat.com
Fri Jul 2 04:04:25 UTC 2004


On Jul  1, 2004, Michal Jaegermann <michal at harddata.com> wrote:

> On Thu, Jul 01, 2004 at 02:23:53PM -0400, John Dennis wrote:
>> 
>> No assumptions should be made about the format of the release string
>> other than it collate correctly when presented to rpmvercmp (the
>> comparison function in rpm which has specific well defined semantics).

> How you are using rpmvercmp, say, in a shell script?  AFAIK there is
> no interface which would make that available.  Or this is one of
> those undocumented mysteries of rpm?

I wrote this years ago for a script that would automatically install
updates from a local mirror of the Red Hat Linux updates site.  Except
that I just updated it to support commas as separators; I'd no idea
they could be used with the same meaning as dots before the internal
discussion :-)

Untested after the change to support commas.  Hope this helps.

# Copyright 1999, 2000, 2001, 2002, 2004
#   Alexandre Oliva <oliva at lsd.ic.unicamp.br>

# This script is Free Software, and it can be copied, distributed and
# modified as defined in the GNU General Public License.  A copy of
# its license can be downloaded from http://www.gnu.org/copyleft/gpl.html

newer () {
  test "x$1" != "x$2" &&
  case "$1$2" in
  *-*)
    newer "`echo $1 | sed 's/-.*//'`" "`echo $2 | sed 's/-.*//'`" ||
    { test "`echo $1 | sed 's/-.*//'`" = "`echo $2 | sed 's/-.*//'`" &&
      newer "`echo $1 | sed 's/[^-]*-*//'`" "`echo $2 | sed 's/[^-]*-*//'`"; }
    ;;
  *[.,]*)
    newer "`echo $1 | sed 's/[.,].*//'`" "`echo $2 | sed 's/[.,].*//'`" ||
    { test "`echo $1 | sed 's/[.,].*//'`" = "`echo $2 | sed 's/[.,].*//'`" &&
      newer "`echo $1 | sed 's/[^.,]*\.*//'`" "`echo $2 | sed 's/[^.,]*\.*//'`"; }
    ;;
  *)
    result=false
    if test -x $SORT; then
      { echo $2; echo $1; } |
        $SORT -n -c > /dev/null 2>&1 && result=true
    else
      test $1 -gt $2 && result=true
    fi
    $result
    ;;
  esac
}

# usage: if newer r1-v1 r2-v2; then echo r1-v1 is newer; fi

-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}





More information about the test mailing list