#!/bin/sh
CWD=$(pwd)
root=/storage/repo/x86_64
outputs=$root/slint-testing/source/global-building/big_upgrade/outputs
mkdir -p $outputs
rm $outputs/*
old=$root/slint-14.2.1/slint
new=$root/slint-testing/slint
cd $old
ls *txz > $outputs/oldpkgs
ls *txz|sed s/-[^-]*-[^-]*-[^-]*$//|sort > $outputs/oldpkgnames
cd $CWD
cd $new
ls *txz > $outputs/newpkgs
ls *txz|sed s/-[^-]*-[^-]*-[^-]*$//|sort > $outputs/newpkgnames
cd $CWD
cd /tmp
diff $outputs/oldpkgnames $outputs/newpkgnames|grep '^>'|sed 's/^> //'| sort > $outputs/added_in_current
diff $outputs/oldpkgnames $outputs/newpkgnames|grep '^<'|sed 's/^< //'| sort > $outputs/removed_from_current
cd $CWD
rm -f $outputs/{upgradedpkgnames,upgrades}
for i in $(<$outputs/oldpkgnames); do
	if grep -wq $i $outputs/newpkgnames; then
	    old=$(grep -w "^${i}-[[:digit:]]" $outputs/oldpkgs)
	    new=$(grep -w "^${i}-[[:digit:]]" $outputs/newpkgs)
		if [ ! "$old" = "$new" ]; then
			echo "$old => $new" >> $outputs/upgrades
			echo $i >> $outputs/upgradedpkgnames
		fi
	fi
done
rm -f $outputs/added_not_installed
for i in $(<$outputs/added_in_current); do
	if [ "$(ls /var/log/packages/*|grep $i)" = "" ]; then
		echo $i >> $outputs/added_not_installed
	fi
done
rm -f $outputs/removed_still_installed
for i in $(<$outputs/removed_from_current); do
	if [ ! "$(ls /var/log/packages/*|grep $i)" = "" ]; then
		echo $i >> $outputs/removed_still_installed
	fi
done
	
