Joey Hess wrote:
> I attach an add_packages file that seems to fix this.

Here's a slightly better version.

-- 
see shy jo
#!/usr/bin/perl -w

use strict;

my $dir = shift;

if (! -d $dir) { 
        die "$dir is not a directory ..."; 
}

my $mirror  = $ENV{'MIRROR'}  || die "Set the MIRROR var ...\n";
my $localdebs = $ENV{'LOCALDEBS'} || $mirror;
my $nonus   = $ENV{'NONUS'}   || '';
my $basedir = $ENV{'BASEDIR'} || die "Set the BASEDIR var ...\n";

require "$basedir/tools/link.pl";

open (LIST, "$basedir/tools/apt-selection cache show @ARGV |") 
                                        || die "Can't fork : $!\n";

$/ = ''; # Browse by paragraph

my ($p, $file, $arch, $d, $realfile, $source, $section, $name);
while (defined($_ = <LIST>)) {
        m/^Package: (\S+)/mi and $p = $1;
        m/^Filename: (\S+)/mi and $file = $1;
        m/^Architecture: (\S+)/mi and $arch = $1;
        m/^Section: (\S+)/mi and $section = $1;

if (! defined $file) {
        print "no file for $_\n";
}

        $source = ($section =~ /non-US/) ? $nonus : $mirror;

        # This is a hack to allow the local debs to be located elsewhere.
        if ($file=~m:local/:) {
                $source=$localdebs;
        }
        # If arch=all, filename may or may not be a symlink.
        # (It used to be one; the Packages files on the archive are now
        # created differently, so the link is dereferenced.)
        # So.. this code is for the case where it is a symlink.
        #   we suppose that the link points to .../binary-all/...
        #   and we reproduce a similar setup on the CD
        if ($arch eq "all" and -l "$source/$file") {
                if ($section =~ /non-US/) {
                        $file =~ m#/([^/]+)$# and $name = $1;
                        symlink ("../binary-all/$name", "$dir/$file");
                } else {
                        $file =~ m#/([^/]+/[^/]+)$# and $name = $1;
                        symlink ("../../binary-all/$name", "$dir/$file");
                }
                $file =~ s#/binary-$ENV{'ARCH'}/#/binary-all/#g;
        }
        # This code is for the case where it is not a symlink.
        # In this case, we need to make a symlink from binary-all to
        # binary-<arch>.
        # But don't mess with local archives in this way.
        elsif ($arch eq "all" && $source ne $localdebs) {
print "DEBUG: arch all, not a link... $file\n";
                my $newfile=$file;
                $newfile =~ s#/binary-all/#/binary-$ENV{'ARCH'}/#g;
                if ($section =~ /non-US/) {
                        # TODO (but it should never happen?)
                        die "sorry, I don't know how to handle this";
                }
                else {
                        $file =~ m#/([^/]+/[^/]+)$# and $name = $1;
print "DEBUG: symlink(../../binary-all/$name to $dir/$newfile)\n";
                        symlink ("../../binary-all/$name", "$dir/$newfile");
                }
        }
        # And we put the file in the CD tree (with a (hard) link)
        $realfile = real_file ("$source/$file");
        good_link ($realfile, "$dir/$file");
}

close LIST or die "Something went wrong with apt-cache : $@ ($!)\n";


Reply via email to