2011-06-10 16:21:32 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#
|
|
|
|
# generate_firmware_task
|
|
|
|
#
|
|
|
|
# Work out which firmware packages we need
|
|
|
|
# Several steps:
|
|
|
|
#
|
|
|
|
# 1. Look for packages which contain "firmware" or "microcode" in their package names
|
|
|
|
# 2. Check each of those packages to see if they contain files in /lib/firmware
|
|
|
|
# 3. For those that do, output the package name into the firmware task
|
|
|
|
#
|
|
|
|
# Copyright Steve McIntyre <93sam@debian.org> 2011
|
|
|
|
#
|
|
|
|
# GPL 2
|
|
|
|
#
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2012-03-05 15:13:17 -01:00
|
|
|
my ($mirror, $codename, $archlist, $outfile, $localdebs);
|
2011-06-10 16:21:32 +00:00
|
|
|
my $date;
|
|
|
|
my $pkgfiles = "";
|
2012-03-05 15:13:17 -01:00
|
|
|
my ($pkg, $filename, $arch);
|
2011-06-10 16:21:32 +00:00
|
|
|
my %seen;
|
|
|
|
|
|
|
|
$codename = $ENV{'CODENAME'};
|
|
|
|
$mirror = $ENV{'MIRROR'};
|
2012-03-05 12:41:01 -01:00
|
|
|
$localdebs = $ENV{'LOCALDEBS'};
|
2011-06-10 16:21:32 +00:00
|
|
|
$archlist = shift;
|
|
|
|
$outfile = shift;
|
|
|
|
|
|
|
|
if (!defined($codename) || !defined($mirror) ||
|
|
|
|
!defined($archlist) || !defined($outfile)) {
|
|
|
|
die "Error in arguments\n";
|
|
|
|
}
|
|
|
|
|
2012-03-05 15:13:17 -01:00
|
|
|
foreach $arch (split(' ', $archlist)) {
|
2012-03-05 12:42:19 -01:00
|
|
|
$pkgfiles = "$pkgfiles $mirror/dists/$codename/*/binary-$arch/Packages.gz";
|
|
|
|
}
|
|
|
|
|
2012-03-05 21:42:30 -01:00
|
|
|
if (defined($localdebs)) {
|
2012-03-05 15:13:17 -01:00
|
|
|
foreach $arch (split(' ', $archlist)) {
|
2012-03-05 12:42:19 -01:00
|
|
|
$pkgfiles = "$pkgfiles $localdebs/dists/$codename/*/binary-$arch/Packages.gz";
|
|
|
|
}
|
2011-06-10 16:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
open (OUT, "> $outfile") or die "Can't open outfile for writing: $!\n";
|
|
|
|
|
|
|
|
$date = `date -u`;
|
|
|
|
chomp $date;
|
|
|
|
|
|
|
|
print OUT "/*\n";
|
|
|
|
print OUT " * 'firmware' task file; generated automatically by generate_firmware_task\n";
|
|
|
|
print OUT " * for \"$archlist\" on $date\n";
|
|
|
|
print OUT " * Do not edit - changes will not be preserved\n";
|
|
|
|
print OUT " */\n";
|
|
|
|
|
|
|
|
print "$0: Checking for firmware packages:\n";
|
|
|
|
|
|
|
|
open (INPKG, "zcat $pkgfiles |") or die "Can't read input package files: $!\n";
|
|
|
|
$/ = ''; # Browse by paragraph
|
|
|
|
|
|
|
|
sub contains_firmware($$) {
|
|
|
|
my $count = 0;
|
|
|
|
open (PKGLISTING, "dpkg --contents $mirror/$filename | grep ' ./lib/firmware/' |") or
|
|
|
|
die "Can't check package file $filename: $!\n";
|
|
|
|
while ($_ = <PKGLISTING>) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
if ($count) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (defined($_ = <INPKG>)) {
|
|
|
|
m/^Package: (\S+)/m and $pkg = $1;
|
|
|
|
m/^Filename: (\S+)/m and $filename = $1;
|
|
|
|
|
|
|
|
if (! ($pkg =~ /(microcode|firmware)/)) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!exists $seen{$filename}) {
|
|
|
|
$seen{$filename} = 1;
|
|
|
|
if (contains_firmware($mirror, $filename)) {
|
|
|
|
print " $pkg ($filename)\n";
|
|
|
|
print OUT "$pkg\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close INPKG;
|
|
|
|
close OUT;
|