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

[PATCH] Support multiple components and non-i386 mirrors in which_deb



I'm working on building some custom CDs, which contain a subset of the 'main', as well as our own component, 'local'. Limitations in which_deb prevent debian-cd from finding our version of debootstrap, in the 'local' component, as it only looks in main. This patch adds support for a 5th (through nth) argument, to specify which components to look in; without this option specified, it looks for all $component/binary-$arch/Packages.gz files, to build a list of components to search.

It's unclear to me whether the optional arguments will ever be useful; I added this in case it was ever important to explicitly exclude contrib, non-free, etc, from these searches. If this is not useful, then it will be simpler to build the @components array dynamically on every invocation.

Additionally, we will likely be completely dropping i386 support for our own custom distribution soon, so I have also modified which_deb to look for i386 *or* amd64 as a $default_arch to be used in place of 'i386' throughout the script.

Perhaps I should have done these two changes as two separate diffs, but at this point I suppose feedback on these two changes is more useful than anything anyway. In particular, whether the 5th argument is something that's important to support.

The multiple-component bit applies to bug #489516, although to completely close that bug, additional changes will be necessary as well--which I would be happy to also work on, so that we aren't forced to use 'local' as our custom component name :)

Thoughts?



--
Inbound and outbound email scanned for spam and viruses by the

DoubleCheck Email Manager: http://www.doublecheckemail.com
Index: which_deb
===================================================================
--- which_deb	(revision 7405)
+++ which_deb	(working copy)
@@ -7,14 +7,31 @@
 
 use strict;
 
-my ($mirror, $codename, $pkg, $pth, $output);
+my ($mirror, $codename, $pkg, $pth, $output, @components);
 
 $mirror = shift;
 $codename = shift;
 $pkg = shift;
 $output = shift;
-$pth = "$mirror/dists/$codename/main";
+@components = @ARGV;
 
+my @default_arch_options = qw(i386 amd64);
+my $default_arch;
+while ( !$default_arch ) {
+    $default_arch = shift @default_arch_options
+        or die "Cannot determine architecture";
+     -e "$mirror/dists/$codename/main/binary-$default_arch"
+        or undef $default_arch;
+}
+
+unless ( @components ) {
+    opendir COMP, "$mirror/dists/$codename";
+    @components = grep { -e "$mirror/dists/$codename/$_/binary-$default_arch/Packages.gz" }
+        readdir COMP;
+    close COMP;
+}
+$pth = "$mirror/dists/$codename/";
+
 if (!defined ($output)) {
     $output = "binary";
 }
@@ -27,23 +44,25 @@
     my $match;
     my $result = "";
     
-    my $pgz = "$pth/binary-$arch/Packages.gz";
+    for my $component ( @components ) {
+        my $pgz = "$pth/$component/binary-$arch/Packages.gz";
 
-    $/ = ''; # Browse by paragraph    
+        $/ = ''; # Browse by paragraph    
 
-    if (-e $pgz) {
-        open(PFILE, "zcat $pgz |") or
-            die "Failed to read Packages file $pgz";
+        if (-e $pgz) {
+            open(PFILE, "zcat $pgz |") or
+                die "Failed to read Packages file $pgz";
 
-        while (defined($match = <PFILE>)) {
-            if (($match =~ /^Package: \Q$pkgname\E$/m)) {
-                $result = $match;
-                close PFILE;
-                return $result;
+            while (defined($match = <PFILE>)) {
+                if (($match =~ /^Package: \Q$pkgname\E$/m)) {
+                    $result = $match;
+                    close PFILE;
+                    return $result;
+                }
             }
+            # Fell through
+            close PFILE;
         }
-        # Fell through
-        close PFILE;
     }
     return "";
 }
@@ -81,15 +100,15 @@
 my $srcname = "";
 
 if ($pkg eq "debootstrap") {
-    $pkgdata = grab_bin_info($pth, "i386", $pkg);
+    $pkgdata = grab_bin_info($pth, $default_arch, $pkg);
 
 } elsif ($pkg eq "silo") {
     $pkgdata = grab_bin_info($pth, "sparc", $pkg);
 
 } elsif ($pkg eq "syslinux") {
-    $pkgdata = grab_bin_info($pth, "i386", "syslinux-common");
+    $pkgdata = grab_bin_info($pth, $default_arch, "syslinux-common");
     if (length($pkgdata) < 3) {        
-        $pkgdata = grab_bin_info($pth, "i386", "syslinux");
+        $pkgdata = grab_bin_info($pth, $default_arch, "syslinux");
     }
 } elsif ($pkg eq "yaboot") {
     $pkgdata = grab_bin_info($pth, "powerpc", $pkg);

Reply to: