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

Re: apt configuration

> > I am trying to make apt always run debsums_gen on the just-installed
> > packages.  I think it should be possible, but the apt.conf manpage is
> > terrible :(  Can anyone give me an example of a setup where some
> > nontrivial shell code runs that way?

Matt> Neither is a shell script, but take a look at dpkg-preconfigure
Matt> for a simple example, or apt-listchanges for a more complex one.

Michael> If you glean some useful information from them, can you
Michael> please send in patches to the manpage?

About the manpage: I don't know if it can be patched, more like
rewritten.  I will have a stab at it someday.  The two general
problems are: it doesn't document the format precisely (it is
certainly NOT perl, with // comments) and the part about how apt
actually calls it is hardly comprehensible at least to an outsider
(what's the difference between Pre-Install-Pkgs and Pre-Invoke, for

Another thing is that debsums_gen is broken by itself, so I had to
roll my own.  Colin: your code is probably better and faster, but I
really wanted to fix md5sums rather than introduce a new mechanism.

Here's what I ended up doing:

in /etc/apt/apt.conf.d/80/80md5sums 

// Massage packages that omit a md5sums file.
// If you don't like it, comment it out.
DPkg::Pre-Install-Pkgs {"xargs /usr/local/sbin/md5sums_deb";};

and this is /usr/local/sbin/md5sums_deb:

#! /usr/bin/perl

use Digest::MD5;
use FileHandle;
use File::Temp qw(tempdir);
use File::Find;

our %conffiles = ();

sub wanted {
    $File::Find::prune = 1 if ($File::Find::name eq "$debdir/etc"
or $File::Find::name eq "$debdir/DEBIAN");
    return unless (-f $File::Find::name);
    my $relname = $File::Find::name;
    $relname =~ s{^\Q$debdir/}{};
    return if $conffiles{$relname};
    my $debfile = FileHandle->new;
    $debfile->open("<$File::Find::name") or die "$File::Find::name: $! \n";
    my $md5_ctx = Digest::MD5->new;
    my $md5_hash = $md5_ctx->hexdigest();
    $md5sums->printf("%s  %s\n", $md5_hash, $relname);

exit 0 if ($#ARGV < 0);
foreach my $deb (@ARGV) {
    local $debdir = tempdir( CLEANUP => 1 );
    $debdir or die "$! \n";
    system("dpkg-deb --extract $deb $debdir") == 0
or die "dpkg-deb exited with status $? \n";
    system("dpkg-deb --control $deb $debdir/DEBIAN") == 0
or die "dpkg-deb exited with status $? \n";
    next DEB if (-f "$debdir/DEBIAN/md5sums");
    printf("%s missing md5sums, generating...", $deb);
    if (-f "$debdir/DEBIAN/conffiles") {
	my $conffiles = FileHandle->new;
or die "$debdir/DEBIAN/conffiles: $! \n";
	foreach my $conffile ($conffiles->getlines()) {
	    $conffile =~ s{^/(.*)}{$1};
	    $conffiles{$conffile} = 1;
    local $md5sums = FileHandle->new;
or die "$debdir/DEBIAN/md5sums: $! \n";
    File::Find::find(\&wanted, $debdir) ;
    system("dpkg-deb --build $debdir $deb") == 0
or die "dpkg-deb exited with status $? \n";

Ian Zimmerman, Oakland, California, U.S.A.
GPG: 433BA087  9C0F 194F 203A 63F7 B1B8  6E5A 8CA3 27DB 433B A087
EngSoc adopts market economy: cheap is wasteful, efficient is expensive.

Reply to: