#!/bin/sh
#
## UPDATE-SYSTEM  -  a simple Debian system updater.
#  
## AUTHORS 
#  Martin Zdrahal <martin.zdrahal@konflux.at> (2003)
#  Martin-Eric Racine <q-funk@iki.fi> (2004)
#  Christoph Schindler <hop@30hopsmax.at> (2004)
#
## HOMEPAGE
#  http://funkyware.konflux.at/
#
## CHANGES
#  2004-09-04   Made orphan purge recursive.	v0.8
#  2004-08-19   Add APT exit code check.	v0.7
#  2004-06-07   Add CLEANOPTS to config.	v0.6
#  2004-03-31   Created config file.		v0.5
#  2004-03-24   Add -y to dist-upgrade.		v0.4
#  2004-03-15   Add --guess-doc --libdevel.	v0.3
#  2004-03-09   Renamed upgrade-system.		v0.2
#  2004-02-16   Initial release.		v0.1
#
. /etc/upgrade-system.conf

echo "Upgrading system:"
echo "1) Updating available package lists."
apt-get -q=2 update
if [ $? != 0 ]
then
	echo "E: Some package lists could not be updated."
	exit 1
fi

echo "2) Upgrading installed packages:"
apt-get $UPGRADEOPTS $1
if [ $? != 0 ]
then
	echo "E: Some packages could not be upgraded."
	exit 2
fi

echo "3) Cleaning APT cache."
apt-get $CLEANOPTS

if [ -f /usr/bin/deborphan ]
then
	echo "4) Checking for orphan files:"

	while /bin/true
	do
		# save the orphan list for later use
		ORPHANS=$( deborphan $ORPHANOPTS )

		case $ORPHANS in
			"")
				echo "No orphan file to be purged."
				break
				;;

			*)
				echo "Purging orphan files..."
				echo $ORPHANS | xargs dpkg --purge
				;;
		esac
	done
fi

if [ -f /usr/bin/update-menus ]
then
	echo "5) Refreshing menus."
	update-menus &
fi

echo "System upgrade completed."

#EoF
