#!/bin/sh
# Returns the newest package from the pkg list (without extension.src.rpm)
last_rpm ()
{
  local i LR
  local lastrpm
  local pkgver
  lastrpm="____NOT_FOUND______"
  if ! which rpmevrcmp >/dev/null 2>&1 ; then
	lastrpm=$(xargs -n1 echo " " | sort | tail -n1)
	# hack against src.rpm
	basename $lastrpm .src.rpm
	exit
  fi
  for i in $(cat); do
	pkgver=$(rpm -qp "$i")
	# hack against broken rpm -qp (rpm-4.13.0-alt3) https://bugzilla.altlinux.org/show_bug.cgi?id=32872
	pkgver=$(echo "$pkgver" | sed -e "s@\.\(noarch\|i[56]86\|x86_64\)\$@@")
	LR=$(rpmevrcmp "$pkgver" "$lastrpm")
	if [ "$LR" -gt 0 ]; then
		lastrpm="$pkgver"
	fi
  done
  echo $lastrpm
}

last_rpm
