--- /usr/sbin/upgrade-system	2004-08-20 02:43:31.000000000 +0200
+++ /upgrade-system_AlberT	2004-08-27 12:35:52.000000000 +0200
@@ -5,11 +5,13 @@
 #  AUTHORS 
 #	Martin Zdrahal <martin.zdrahal@konflux.at> (2003)
 #	Martin-Eric Racine <q-funk@iki.fi> (2004)
+#	Emiliano Gabrielli <AlberT@SuperAlberT.it> (2004)
 #
 #  HOMEPAGE
 #	http://funkyware.konflux.at/
 #
 #  CHANGES
+#	2004-08-19   Recursive packets purge.	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
@@ -42,12 +44,22 @@
 if [ -f /usr/bin/deborphan ]
 then
 	echo -e "\nChecking for orphan files..."
-	if [ `deborphan $ORPHANOPTS | wc -l | tr -d " "` = 0 ];
+	# purge until we have packages to purge.
+	# we do it in a recursive way becouse removing a package
+	# can generate other orphans not taken in account in the 
+	# previous step
+	for (( i=0; `deborphan $ORPHANOPTS | wc -l | tr -d " "` ; ));
+	do
+		if (( $i==0 ))
+		then
+			echo "Purging orphan files..."
+			i=($i+1)
+		fi
+		deborphan $ORPHANOPTS | xargs dpkg --purge
+	done
+	if (( $i==0 ))
 	then
 		echo "No orphan file to be purged."
-	else
-		echo "Purging orphan files..."
-		deborphan $ORPHANOPTS | xargs dpkg --purge
 	fi
 fi
 

