Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dpkg --compare-versions

0 views
Skip to first unread message

Michael Merten

unread,
Jun 1, 1999, 3:00:00 AM6/1/99
to
Hi,

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...

-------------------------------------------------------------------
#!/bin/bash
#
oldfile=``
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
oldfile=$file
else
echo delete $file keep $oldfile
fi
else
oldfile=$file
fi
done
----------------------------------------------------------------------

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

----------------------------------------------------------------------
[snip]
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
[snip]
----------------------------------------------------------------------

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)

Mike

--
Michael Merten iron...@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)]


--
To UNSUBSCRIBE, email to debian-dev...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Craig Sanders

unread,
Jun 2, 1999, 3:00:00 AM6/2/99
to
On Tue, Jun 01, 1999 at 06:28:36PM -0500, Michael Merten wrote:
> delete sharutils_1%3a4.2-10_i386.deb keep sharutils_4.2-9.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...

looks like apt is saving the URL-encoded form of the filename.

%3a is character 0x3a, or ":".

i.e. "sharutils_1%3a4.2-10_i386.deb" is sharutils version 1:4.2-10


maybe you should convert it back by using sed in the pipeline:

e.g.
v1= ... | sed -e 's/\%3a/:/g' | ....
v2= ... | sed -e 's/\%3a/:/g' | ....

craig

--
craig sanders

Jason Gunthorpe

unread,
Jun 2, 1999, 3:00:00 AM6/2/99
to

On Tue, 1 Jun 1999, Michael Merten wrote:

> 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...

You do realize that this is exactly what the apt-get autoclean feature
does?

The trouble you are having is that APT renames files to their proper full
name including arch and epochs by escaping special characters with a %,
when it goes to re-read the directory it can reassemble the correct
versions of everything.

Autoclean removes any version that is no longer present in the archive
which is one step further than what you are doing here.

Jason

Michael Merten

unread,
Jun 2, 1999, 3:00:00 AM6/2/99
to
On Wed, Jun 02, 1999 at 10:30:41AM +1000, Craig Sanders wrote:
> On Tue, Jun 01, 1999 at 06:28:36PM -0500, Michael Merten wrote:
> > delete sharutils_1%3a4.2-10_i386.deb keep sharutils_4.2-9.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...
>
> looks like apt is saving the URL-encoded form of the filename.
>
> %3a is character 0x3a, or ":".
>
> i.e. "sharutils_1%3a4.2-10_i386.deb" is sharutils version 1:4.2-10
>
>
> maybe you should convert it back by using sed in the pipeline:
>
> e.g.
> v1= ... | sed -e 's/\%3a/:/g' | ....
> v2= ... | sed -e 's/\%3a/:/g' | ....
>
> craig
>
Thanks... I knew I was missing something :)

Mike

--
Michael Merten iron...@popaccount.com NRA Life Member
---------------------------------------------------------------------

South Carolina State Constitution: A well regulated militia being
necessary to the security of a free State, the right of the people to
keep and bear arms shall not be infringed. As, in times of peace,
armies are dangerous to liberty, they shall not be maintained without
the consent of the General Assembly. The military power of the State
shall always be held in subordination to the civil authority and be
governed by it. No soldier shall in time of peace be quartered in any
house without the consent of the owner nor in time of war but in the
manner prescribed by law. (Art. I, Sect. 20)
[NRA-ILA (www.nraila.org)]

--
This signature was automatically generated with Signify v1.05.
For this and other cool products, check out http://www.debian.org/.

Michael Merten

unread,
Jun 2, 1999, 3:00:00 AM6/2/99
to
On Tue, Jun 01, 1999 at 07:16:33PM -0600, Jason Gunthorpe wrote:
>
> On Tue, 1 Jun 1999, Michael Merten wrote:
>
> > 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...
>
> You do realize that this is exactly what the apt-get autoclean feature
> does?
>
> The trouble you are having is that APT renames files to their proper full
> name including arch and epochs by escaping special characters with a %,
> when it goes to re-read the directory it can reassemble the correct
> versions of everything.
>
> Autoclean removes any version that is no longer present in the archive
> which is one step further than what you are doing here.
>
> Jason

I was under the impression (from reading "man apt.conf") that the auto
option wasn't working, at this time... I'll go back and have a look
at it.

Thanks,
Mike


--
Michael Merten iron...@popaccount.com NRA Life Member
---------------------------------------------------------------------

"Guard with jealous attention the public liberty. Suspect everyone
who approaches that jewel." -- Patric Henry -- Virginia's U.S.
Constitution ratification convention
[NRA-ILA (www.nraila.org)]

Michael Merten

unread,
Jun 2, 1999, 3:00:00 AM6/2/99
to
On Wed, Jun 02, 1999 at 02:46:44AM -0500, Michael Merten wrote:
> On Wed, Jun 02, 1999 at 10:30:41AM +1000, Craig Sanders wrote:
> > On Tue, Jun 01, 1999 at 06:28:36PM -0500, Michael Merten wrote:
> > > delete sharutils_1%3a4.2-10_i386.deb keep sharutils_4.2-9.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...
> >
> > looks like apt is saving the URL-encoded form of the filename.
> >
> > %3a is character 0x3a, or ":".
> >
> > i.e. "sharutils_1%3a4.2-10_i386.deb" is sharutils version 1:4.2-10
> >
> >
> > maybe you should convert it back by using sed in the pipeline:
> >
> > e.g.
> > v1= ... | sed -e 's/\%3a/:/g' | ....
> > v2= ... | sed -e 's/\%3a/:/g' | ....
> >
> > craig
> >
> Thanks... I knew I was missing something :)
>
> Mike

Sorry to reply to my own message, but I've run into another problem...
if I manually type the following:

dpkg --compare-versions sharutils_1:4.2.10_i386.deb lt \
sharutils_4.2.9.deb

(all on one line in actual usage) it produces the following error
message:

version a has bad syntax: epoch in version is not number

Any suggestions here?

Mike

--
Michael Merten iron...@popaccount.com NRA Life Member
---------------------------------------------------------------------

"The militia, who are in fact the effective part of the people at
large, will render many troops quite unnecessary. They will form a
powerful check upon the regular troops, and will generally be
sufficient to over-awe them." -- Tench Coxe -- An American Citizen,
Oct. 21, 1787

Antti-Juhani Kaijanaho

unread,
Jun 2, 1999, 3:00:00 AM6/2/99
to
On Wed, Jun 02, 1999 at 03:37:52AM -0500, Michael Merten wrote:
> dpkg --compare-versions sharutils_1:4.2.10_i386.deb lt \
> sharutils_4.2.9.deb

Wrong syntax.

dpkg --compare-versions 1:4.2.10 lt 4.2.9

is correct. --compare-versions compares versions, not file names.

--
%%% Antti-Juhani Kaijanaho % ga...@iki.fi % http://www.iki.fi/gaia/ %%%

"... memory leaks are quite acceptable in many applications ..."
(Bjarne Stroustrup, The Design and Evolution of C++, page 220)

Michael Merten

unread,
Jun 2, 1999, 3:00:00 AM6/2/99
to
On Wed, Jun 02, 1999 at 01:45:47PM +0300, Antti-Juhani Kaijanaho wrote:
> On Wed, Jun 02, 1999 at 03:37:52AM -0500, Michael Merten wrote:
> > dpkg --compare-versions sharutils_1:4.2.10_i386.deb lt \
> > sharutils_4.2.9.deb
>
> Wrong syntax.
>
> dpkg --compare-versions 1:4.2.10 lt 4.2.9
>
> is correct. --compare-versions compares versions, not file names.
>
> --
> %%% Antti-Juhani Kaijanaho % ga...@iki.fi % http://www.iki.fi/gaia/ %%%
>
> "... memory leaks are quite acceptable in many applications ..."
> (Bjarne Stroustrup, The Design and Evolution of C++, page 220)
>

Ok, I modified my script to trim the package name from the version
and use the result when calling dpkg and it seems to work like I
wanted it to. Thanks!

Mike

--
Michael Merten iron...@popaccount.com NRA Life Member
---------------------------------------------------------------------

"Get your facts first, and then you can distort them as much as you
please." --Mark Twain
[The Federalist (www.Federalist.com)]

--
This signature was automatically generated with Signify v1.05.
For this and other cool products, check out http://www.debian.org/.

Michael Merten

unread,
Jun 2, 1999, 3:00:00 AM6/2/99
to
On Wed, Jun 02, 1999 at 02:49:58AM -0500, Michael Merten wrote:
> On Tue, Jun 01, 1999 at 07:16:33PM -0600, Jason Gunthorpe wrote:
> >
> > On Tue, 1 Jun 1999, Michael Merten wrote:
> >
> > > 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...
> >
> > You do realize that this is exactly what the apt-get autoclean feature
> > does?
> >
> > The trouble you are having is that APT renames files to their proper full
> > name including arch and epochs by escaping special characters with a %,
> > when it goes to re-read the directory it can reassemble the correct
> > versions of everything.
> >
> > Autoclean removes any version that is no longer present in the archive
> > which is one step further than what you are doing here.
> >
> > Jason
>
> I was under the impression (from reading "man apt.conf") that the auto
> option wasn't working, at this time... I'll go back and have a look
> at it.
>
> Thanks,
> Mike
>

Ok, my mistake... I attempted to RTFM before doing this, but it seems the
FM isn't quite up-to-date on this subject. ;) I took a look at the
/usr/lib/dpkg/methods/apt/install script and it does correctly call
apg-get autoclean now (dangit... I distinctly remember looking at it last
year and it seeing apt-get clean in there. ;/ )

Ah well, live 'n learn.


Thanks,
Mike

--
Michael Merten iron...@popaccount.com NRA Life Member
---------------------------------------------------------------------

"The price of freedom is eternal vigilance" --Thomas Jefferson
[The Federalist (www.Federalist.com)]

0 new messages