1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
#!/usr/bin/perl
# Generate a list of packages required for debian-installer
# This script makes use of the following variables that need to be preset:
# MIRROR, DI_CODENAME, BASEDIR
use strict;
use warnings;
die "Missing \$MIRROR variable" unless $ENV{MIRROR};
die "Missing \$DI_CODENAME variable" unless $ENV{DI_CODENAME};
die "Missing \$BASEDIR variable" unless $ENV{BASEDIR};
die "Missing \$ARCHES variable" unless $ENV{ARCHES};
my $catz = $ENV{BASEDIR} . "/tools/catz";
# Early exit if we're building a source-only CD
exit 0 if $ENV{ARCHES} =~ /^\s*source\s*$/;
my @ARCHES;
if ( $ENV{ARCHES} ) {
push @ARCHES, 'i386' if $ENV{ARCHES} =~ /(^|\s)i386(\s|$)/;
push @ARCHES, 'amd64' if $ENV{ARCHES} =~ /(^|\s)amd64(\s|$)/;
push @ARCHES, grep { !/^(source|i386|amd64)$/ } split /\s+/, $ENV{ARCHES};
}
@ARCHES = qw{i386 amd64} unless @ARCHES;
my @VARIANTS;
if ( $ENV{VARIANTS} ) {
@VARIANTS = split(" ", $ENV{VARIANTS});
}
my $DATE=`date`;
chomp $DATE;
open(OUT, ">debian-installer") || die "write: $!";
print OUT << "EOF";
/* List of udebs to be included so that debian-installer works fine
*
* This list can be generated with the command:
* ../tools/generate_di_list
*
* DO NOT EDIT THIS FILE, edit the above script
*
* Last update: $DATE
*/
EOF
sub di_ker_abi_to_number ($$$$) {
# Make up a version we can compare sensibly from
# the version and ABI
my $maj = shift;
my $min = shift;
my $patch = shift;
my $abi = shift;
my $kernel_ver = ($maj * 1000000000)
+ ($min * 1000000)
+ ($patch * 1000)
+ $abi;
return $kernel_ver;
}
sub number_to_di_ker_abi ($) {
# Convert back to a useful string
my $num = shift;
my $maj = int($num / 1000000000);
$num -= ($maj * 1000000000);
my $min = int($num / 1000000);
$num -= ($min * 1000000);
my $patch = int($num / 1000);
$num -= ($patch * 1000);
my $abi = $num;
return "$maj.$min.$patch-$abi";
}
my @common_excludes = read_exclude("exclude-udebs");
my $mirror_path = "$ENV{MIRROR}/dists/$ENV{DI_CODENAME}";
my @components = qw(main);
push @components, 'contrib' if $ENV{CONTRIB};
if ($ENV{NONFREE}) {
push @components, split /\ /,$ENV{NONFREE_COMPONENTS};
}
push @components, 'unreleased' if $ENV{UNRELEASED};
push @components, 'local' if $ENV{LOCAL};
foreach my $arch (@ARCHES) {
(my $cpparch = $arch) =~ s/-/_/g;
my $output = '';
for my $component ( @components ) {
my $pgz="$mirror_path/$component/debian-installer/binary-$arch/Packages.gz";
my $pxz="$mirror_path/$component/debian-installer/binary-$arch/Packages.xz";
if ( $component eq 'unreleased' and $ENV{UNRELEASED} ) {
$pgz="$ENV{MIRROR}/dists/unreleased/main/debian-installer/binary-$arch/Packages.gz";
$pxz="$ENV{MIRROR}/dists/unreleased/main/debian-installer/binary-$arch/Packages.xz";
}
if ( $component eq 'local' and $ENV{LOCALDEBS} ) {
$pgz="$ENV{LOCALDEBS}/dists/$ENV{DI_CODENAME}/local/debian-installer/binary-$arch/Packages.gz";
$pxz="$ENV{LOCALDEBS}/dists/$ENV{DI_CODENAME}/local/debian-installer/binary-$arch/Packages.xz";
}
my @exclude = @common_excludes;
push @exclude, read_exclude("exclude-udebs-$arch")
if -e exclude_path("exclude-udebs-$arch");
my $pz = $pgz;
if (! -f $pz) {
$pz = $pxz;
}
if (! -f $pz) {
print "Missing package file for $arch/$component.\n";
next;
}
# Two passes here
# First, need to find the highest kernel ABI in the archive
# Next, list all the udebs that:
# 1. are not otherwise excluded
# 2. are not kernel driver udebs, OR
# are kernel driver udebs with the right kernel ABI
unless ( open (PZ, "$catz $pz |") ) {
warn "failed to read package file $pz: $1";
next;
}
my @output_udebs;
my %driver_udebs;
my $highest_kernel_ver = 0;
while (defined (my $line = <PZ>)) {
chomp $line;
if ($line =~ m/^Package: (\S+)/) {
my $udeb = $1;
if (grep { $udeb =~ /^${_}$/ } @exclude) {
next;
}
if ($udeb =~ m/-modules-(\d+)\.(\d+)\.(\d+)-(\d+)-.*-di/) {
# Older udeb package names included the ABI here
my $kernel_ver = di_ker_abi_to_number($1, $2, $3, $4);
if ($kernel_ver > $highest_kernel_ver) {
$highest_kernel_ver = $kernel_ver;
}
# Append this driver udeb to a list for that kernel_ver
push(@{ $driver_udebs{$kernel_ver} }, $udeb);
} elsif ($udeb =~ m/-modules-(\d+)\.(\d+)\.(\d+)-.*-di/) {
# Newer udeb package names don't, so use "0" as a dummy value here
my $kernel_ver = di_ker_abi_to_number($1, $2, $3, 0);
if ($kernel_ver > $highest_kernel_ver) {
$highest_kernel_ver = $kernel_ver;
}
# Append this driver udeb to a list for that kernel_ver
push(@{ $driver_udebs{$kernel_ver} }, $udeb);
} else {
#print "found non-driver udeb $udeb\n";
push @output_udebs, $udeb;
}
}
}
close PZ;
$output .= "/* Udebs found in $pz: */\n";
if (scalar (@output_udebs) > 0) {
$output .= "/* Non-kernel udebs */\n";
foreach my $udeb (@output_udebs) {
$output .= "$udeb\n";
}
}
if ($highest_kernel_ver != 0) {
my $num_this_abi = scalar (@{ $driver_udebs{$highest_kernel_ver}});
$output .= "/* Next: $num_this_abi udebs for kernel/ABI version ";
$output .= number_to_di_ker_abi($highest_kernel_ver);
$output .= " */\n";
foreach my $udeb (@{ $driver_udebs{$highest_kernel_ver}}) {
$output .= "$udeb\n";
}
foreach my $key (keys (%driver_udebs)) {
if ($key != $highest_kernel_ver) {
$num_this_abi = scalar (@{ $driver_udebs{$key}});
$output .= "/* IGNORING $num_this_abi udebs for kernel/ABI version ";
$output .= number_to_di_ker_abi($key);
$output .= " */\n";
}
}
}
}
next unless $output;
print OUT "#ifdef ARCH_$cpparch\n";
print OUT $output;
print OUT "#endif /* ARCH_$cpparch */\n";
}
sub read_exclude {
my $file=exclude_path(shift);
unless ( open (IN, "<$file") ) {
warn "failed to read exclude file $file";
return;
}
my @ret;
while (<IN>) {
chomp;
s/^#.*//;
next unless length;
my ($pkg,@cond) = split(" ", $_);
my $skip = 0;
foreach my $cond ( @cond ) {
if ($cond =~ /^!(.*)/) {
$skip = 1 if grep { $_ eq $1 } @VARIANTS;
} else {
$skip = 1 unless grep { $_ eq $cond } @VARIANTS;
}
}
next if $skip;
$pkg=quotemeta($pkg);
$pkg=~s/\\\*/.*/g;
push @ret, $pkg;
}
close IN;
return @ret;
}
sub exclude_path {
my $file=shift;
return "$ENV{BASEDIR}/data/$ENV{DI_CODENAME}/$file";
}
|