4 unshift @INC, ($::ENV{"BUILD_DIR"} || "/usr/lib/build");
15 Getopt::Long::Configure("no_ignore_case");
20 # distribution: <baseurl>/<dist>/[components]
21 # flat repo: <baseurl>/.
23 my $cachedir = "/var/cache/build";
26 GetOptions('cachedir=s' => \$cachedir, 'archpath=s' => \$archpath) or exit(1);
29 $archpath = `uname -p` || 'unknown';
32 my $basearch = $archpath;
34 $basearch = Build::Deb::basearch($basearch);
38 die("$url: not an remote debian repo\n") unless $url =~ /^(:?ftps?|https?):\/\/([^\/]*)\/?/;
39 my $repoid = Digest::MD5::md5_hex($url);
40 my $dir = "$cachedir/$repoid";
45 if ($url =~ /^(.*\/)\.(\/.*)?$/) {
49 $url = defined($2) ? "$1$2" : $1;
50 $url .= '/' unless $url =~ /\/$/;
52 if ($url =~ /([^\/]+)$/) {
53 @components = split(/[,+]/, $1);
54 $url =~ s/([^\/]+)$//;
56 push @components, 'main' unless @components;
57 $url .= '/' unless $url =~ /\/$/;
59 $url =~ s/([^\/]+\/)$/dists\/$1/;
60 $baseurl =~ s/([^\/]+\/)$//;
63 File::Path::mkpath($dir);
64 for my $component (@components) {
65 unlink("$dir/Packages.gz");
66 if ($component eq '.') {
67 system($INC[0]."/download", $dir, "${url}Packages.gz");
68 die("Packages.gz missing\n") unless -s "$dir/Packages.gz";
70 system($INC[0]."/download", $dir, "$url$component/binary-$basearch/Packages.gz");
71 die("Packages.gz missing for basearch $basearch, component $component\n") unless -s "$dir/Packages.gz";
73 Build::Debrepo::parse("$dir/Packages.gz", sub {
75 $_[0]->{'id'} = "$pkgnum/0/0";
76 Build::writedeps(\*STDOUT, $_[0], $baseurl);
77 }, 'addselfprovides' => 1);