#!/bin/bash

# Program to check for update rpm's that should be applied to a RedHat system.
# rpm's to test are passed on command line.  For sparc, alpha, ppc, or noarch
# rpm's, change the SUFFIX variable as appropriate.
# 
# Written by:  Chris Studholme
# Last Update: 8-Jan-1999
# Copyright:   GPL (http://www.fsf.org/copyleft/gpl.html)

SUFFIX='[.]i386[.]rpm'
export SUFFIX
rvalue=1

for file in $*; do
  if [ -f $file ]; then
    if echo $file|grep $SUFFIX>/dev/null; then
	update=`echo $file|sed -e "s/$SUFFIX//"`
	rpm=`echo $update|sed -e 's/-[0-9]*$//'`
	newver=`echo $update|sed -e 's/.*-//'`
	query=`rpm -q $rpm 2>/dev/null`
	if [ "$query" = "" ]; then
	  # package is not installed
	  :
	else
	  oldver=`echo $query|sed -e 's/.*-//'`
	  if [ "$newver" = "$oldver" ]; then
	    # package is up-to-date
	    :
	  else
	    # package needs updating
	    rvalue=0
	    echo $file should be applied to update from revision $oldver
	  fi
	fi
    fi
  fi
done

exit $rvalue
