#!/bin/bash
#
# Upgrade
# Version 1.2.2
# (C) 1997 (19970711) by Roar Thronęs
# Freely redistributable, no warranty. Read before use.
# Stand in the directory with the new rpms.
#

echo "Reinstall all packages (yY)/Just new ones(!yY) ?"
read CHOICE
case $CHOICE in
 [yY] )
	ANSW=YES
	echo Reinstalling all current packages 
	echo
	;;
 * )
	ANSW=NO
	echo Upgrading to just the new ones
	echo 
 	;;
esac

rpm -q -a > /tmp/rpms

[ -f /tmp/newone ] && rm /tmp/newone
touch /tmp/newone
[ -f /tmp/newone2 ] && rm /tmp/newone2
touch /tmp/newone2
[ -f /tmp/newone3 ] && rm /tmp/newone3
touch /tmp/newone3

for X in `cat /tmp/rpms`; do
 if [ "X$ANSW" = "XYES" ] || [ ! -f $X.i386.rpm -a ! -f $X.noarch.rpm ]; then
  echo $X >> /tmp/newone
 fi;
done

ed - /tmp/newone > /dev/null <<_
1,\$s/\-[0-9\.A-Za-z]*\-[0-9\.A-Za-z]*$//
w
q
_

for X in `cat /tmp/newone`; do
if [`ls $X-*|wc -l` = 1 ]; then
	echo `ls $X-*` >> /tmp/newone2
else
PACK=`rpm -q --info $X | head -1 | cut -f2 -d: | cut -f2 -d\ `
for Y in `ls $X-*`; do
NEW=`rpm -qp --info $Y | head -1 | cut -f2 -d: | cut -f2 -d\ `
 [ "X$NEW" = "X$PACK" ] && echo $Y >> /tmp/newone2
done
fi
done

echo press enter
read Z
vi /tmp/newone2
cat /tmp/newone2|sort|uniq > /tmp/newone3

for Y in `cat /tmp/newone3`; do
 echo Trying to upgrade
 rpm -U -v --force --nodeps -h $Y
 echo
done

echo Done
echo
