DEFAULT=SL
echo `date` >> errata.log
echo `date` >> new.log
mv *debuginfo*.rpm ../../../archive/debuginfo/
/bin/mv -f *src.rpm ../../../SRPMS/vendor/
for i in *.rpm
do
	if [ -f ../../$DEFAULT/$i ] ; then
		echo "Already have $i in $DEFAULT, so deleting it."
		rm $i
		continue
	fi
	if [ -f ../../../archive/obsolete/$i ] ; then
		echo "Already have $i in obsolete, so deleting it."
		rm $i
		continue
	fi
	NEWNAME=`rpm -qp $i --qf "%{name}"`
	NEWARCH=`rpm -qp $i --qf "%{arch}"`
	OLDRPM=""
	cd ../../$DEFAULT/ > /dev/null
	LIST=`ls -1 ${NEWNAME}* 2> /dev/null`
	for line in $LIST
	do
		OLDNAME=`rpm -qp $line --qf "%{name}"`
		if [ "${OLDNAME}" == "${NEWNAME}" ] ; then
			OLDARCH=`rpm -qp $line --qf "%{arch}"`
			if [ "${OLDARCH}" == "${NEWARCH}" ] ; then
				OLDRPM="$line"
				#echo "Found a match: $line"
			fi
		fi
	done
	cd - > /dev/null
	if [ "$OLDRPM" == "" ] ; then
		echo ""	
		echo "new: $i"
		echo "I could not find a match for this.  Should I just move it in?"
		echo "Enter skip if I should skip this one"
		read new
		 if [ -n "$new" ] ; then
			if [ $new = "skip" ] ; then
				echo "... Skipping"
	        fi	
		 else
			echo "Moving it in"
			mv -v $i ../../$DEFAULT/
			echo -e "\t$i" >> new.log  
		 fi
	else
		echo ""
		echo "old: $OLDRPM"
		echo "new: $i"
		echo "Should I replace the old rpm with the new?"
		echo "Enter skip if I should skip this one"
		read new
		 if [ -n "$new" ] ; then
			if [ $new = "skip" ] ; then
				echo "... Skipping"
	        fi	
		 else
			echo "Replacing old with new"
			mv -v ../../$DEFAULT/$OLDRPM ../../../archive/obsolete/
			mv -v $i ../../$DEFAULT/
			echo -e "\t$i" >> errata.log
		 fi
	 fi
done
