File: generate_firmware_task

package info (click to toggle)
debian-cd 3.1.17
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,056 kB
  • ctags: 180
  • sloc: sh: 5,391; perl: 3,927; makefile: 388
file content (94 lines) | stat: -rwxr-xr-x 2,347 bytes parent folder | download | duplicates (2)
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
#!/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;

my ($mirror, $codename, $archlist, $outfile, $localdebs);
my $date;
my $pkgfiles = "";
my ($pkg, $filename, $arch);
my %seen;

$codename = $ENV{'CODENAME'};
$mirror = $ENV{'MIRROR'};
$localdebs = $ENV{'LOCALDEBS'};
$archlist = shift;
$outfile = shift;

if (!defined($codename) || !defined($mirror) ||
    !defined($archlist) || !defined($outfile)) {
    die "Error in arguments\n";
}

foreach $arch (split(' ', $archlist)) {
    $pkgfiles = "$pkgfiles $mirror/dists/$codename/*/binary-$arch/Packages.gz";
}

if (defined($localdebs)) {
    foreach $arch (split(' ', $archlist)) {
        $pkgfiles = "$pkgfiles $localdebs/dists/$codename/*/binary-$arch/Packages.gz";
    }
}

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;