[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

dpkg --compare-versions


I set up the /etc/apt/apt.conf file to turn off the autoclean feature
when using dselect, and as a result, my /var/cache/apt/archives
directory is growing quite large.  I decided to write a script that 
uses "dpkg --compare-versions" automatically clean out the older
versions of package files.  Here's the script I came up with...
it doesn't actually delete anything yet...

for file in `ls *.deb`; do
	# first, make sure oldfile and file are copies of the same package
	v1=`echo $oldfile | awk '{ split($0,base,"_"); print base[1] }'`
	v2=`echo $file | awk '{ split($0,base,"_"); print base[1] }'`
	if [ "$v1" = "$v2" ]; then
		if `dpkg --compare-versions $oldfile lt $file`; then
			echo delete $oldfile keep $file
			echo delete $file keep $oldfile

I browsed through the output and it looked good, except for one particular

delete sgml-data_0.14_all.deb keep sgml-data_0.17_all.deb
delete sgml-data_0.17_all.deb keep sgml-data_0.18_all.deb
delete sharutils_1%3a4.2-10_i386.deb keep sharutils_4.2-9.deb
delete slashem_0.0.4E5-2.deb keep slashem_0.0.4E5-4_i386.deb
delete slib_2c5-2.deb keep slib_2c5-3_all.deb
delete sp_1.3.3-1.2.1-5.deb keep sp_1.3.3-1.2.1-6_i386.deb

The line for sharutils seems to indicate that the newer version will
be deleted.  dpkg -s sharutils says I have version 1:4.2-10 installed, 
so it would seem to have worked right atleast once...

My question... am I doing something wrong, or is dpkg getting confused by 
the odd version numbering? (or possibly did apt rename the package after
downloading it?)

(sorry for the long post)


Michael Merten        ironfoot@popaccount.com         NRA Life Member
"As the military forces which must occasionally be raised to defend
our country, might pervert their power to the injury of their fellow
citizens, the people are confirmed by the next article (of amendment)
in their right to keep and bear their private arms." -- Tench Coxe --
Federal Gazette, June 18, 1789
[NRA-ILA (www.nraila.org)]

Reply to: