Comment 2 for bug 1342716

Dmitry Ilyin (idv1985) wrote :

How to check versions:

UBUNTU:

dpkg --compare-versions "${a}" "lt" "${b}"

if [ $? -eq "0" ]; then
  echo "${a} < ${b}"
else
  echo "${a} >= ${b}"
fi

CENTOS:

yum install rpmdevtools

rpmdev-vercmp $a $b

PUPPET:

  def versioncmp(version_a, version_b)
    vre = /[-.]|\d+|[^-.\d]+/
    ax = version_a.scan(vre)
    bx = version_b.scan(vre)

    puts ax.inspect
    puts bx.inspect

    while (ax.length>0 && bx.length>0)
      a = ax.shift
      b = bx.shift

      puts "#{a} vs #{b}"

      if( a == b ) then next
      elsif (a == '-' && b == '-') then next
      elsif (a == '-') then return -1
      elsif (b == '-') then return 1
      elsif (a == '.' && b == '.') then next
      elsif (a == '.' ) then return -1
      elsif (b == '.' ) then return 1
      elsif (a =~ /^\d+$/ && b =~ /^\d+$/) then
        if( a =~ /^0/ or b =~ /^0/ ) then
          return a.to_s.upcase <=> b.to_s.upcase
        end
        return a.to_i <=> b.to_i
      else
        return a.upcase <=> b.upcase
      end
    end
    version_a <=> version_b;
  end

 puts versioncmp('2014.1.fuel5.0-mira4', '2014.1.1.fuel5.1-mira0')