Hey folks,

Sorry for breathing new life into this kind of old bug, but this whole wildcard 
thing was something I was looking for myself.  Basically, as an interim 
solution, I've written some rather hackish Perl that does the job for me using 
'apt-cache search' to do the wildcard matching.  While not wonderful, it works 
quite nicely for me and I thought I'd share it just in case it helps anybody 
else who stumbles across this bug page (like I did).

The attached script is configured for stable (priority 500) with my own local 
repo (priority 1000), volatile, backports.org and unofficial multimedia (all 
default priority 10), defined in %repos.  %pins then defines the packages I 
want in each %repo entry to be pinned, in this instance, all linux-2.6.30 and 
openoffice packages from backports, clamav from volatile, and a few things from 
multimedia.  @pinkeys and @repokeys just holds the hash keys so the script 
knows which bits to process and which to ignore (if any).  The preferences get 
written to stdout, so you can check it before writing a file.

Usual disclaimer, works fine for me, may not for you, do what you like with it, 
may kill your dog, not my fault, etc.

Cheers,

Chris Mortimore

#!/usr/bin/perl

# Package pins
#       Format: key = souce ID (from %repos)
#               value = [package,package,package]:[priority]
my %pins = (
        "backports", 
"linux-.*2.6.30.*,.*openoffice.org.*,ttf-opensymbol,uno-libs3,ure:600",
        "volatile", ".*clamav.*:600",
        "multimedia", ".*acroread.*,libdvdcss2,w32codecs:600",
);
# Keys of %pins to process
@pinkeys = ("backports", "volatile", "multimedia");

# Repo definitions
#       Format: key = ID used in pins
#               value = [release pin]:[default priority]
my %repos = (
        "debian", "l=Debian,a=stable:500",
        "security", "l=Debian-Security:500",
        "local", "l=Local:1000",
        "volatile", "l=debian-volatile:10",
        "multimedia", "l=Unofficial Multimedia Packages:10",
        "backports", "l=Backports.org archive:10",
);
# Keys of %repos to process
@repokeys = ("debian", "security", "local", "volatile", "multimedia", 
"backports");

# Process %pins
foreach my $pin (@pinkeys) {
        my ($tmppkgs, $priority) = split(":", $pins{$pin});
        my ($release, undef) = split(":", $repos{$pin});
        my @pkglist = split(",", $tmppkgs);
        my @pkgs = "";

        # Resolve wildcards
        foreach my $pkg (@pkglist) {
                $pkg = "^$pkg\$";
                foreach my $line (`apt-cache --names-only search $pkg`) {
                        $line =~ s/\n//g;
                        my ($name, undef) = split(" ", $line);
                        push(@pkgs, $name);
                }
        }

        # Make a preferences entry
        foreach my $pkg (@pkgs) {
                next if($pkg =~ m/^$/);
                printf("Package: $pkg\nPin: release $release\nPin-Priority: 
$priority\n\n");
        }
        printf("\n");
}

# Process %repos
foreach my $pin (@repokeys) {
        my ($release, $priority) = split(":", $repos{$pin});
        printf("Package: *\nPin: release $release\nPin-Priority: 
$priority\n\n");
}

Reply via email to