2021-07-25 04:46:08 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# © 2021 Cyril Brulebois <kibi@debian.org>
|
|
|
|
#
|
2021-07-25 05:17:50 +00:00
|
|
|
# Generate ready-to-use .patterns files so that one can use grep to
|
2021-07-25 04:46:08 +00:00
|
|
|
# perform hardware to firmware-package lookups in the installer
|
|
|
|
# (see MODALIAS= lines in `udevadm info --export-db`), see the
|
|
|
|
# hw-detect component.
|
|
|
|
#
|
|
|
|
# Parameters: dists/<suite>/*/dep11/Components-<arch>.yml.(gz|xz)
|
|
|
|
#
|
|
|
|
# We're limiting ourselves to packages announcing Type: firmware, and
|
|
|
|
# they need to include such information in their metadata, e.g.
|
2021-07-25 05:18:38 +00:00
|
|
|
# src:firmware-nonfree; the --test option can be used until such
|
|
|
|
# packages appear in the archive.
|
|
|
|
#
|
|
|
|
# See: https://salsa.debian.org/kernel-team/firmware-nonfree/-/merge_requests/19
|
2021-07-25 04:46:08 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2021-07-25 05:10:34 +00:00
|
|
|
use File::Path qw(make_path);
|
2021-07-25 04:46:08 +00:00
|
|
|
use File::Slurp;
|
2021-07-25 04:52:13 +00:00
|
|
|
use Getopt::Long;
|
2021-07-25 04:46:08 +00:00
|
|
|
use YAML::XS;
|
|
|
|
|
2021-07-25 05:16:56 +00:00
|
|
|
|
|
|
|
# XXX: Drop support for --test once we have the required metadata in
|
|
|
|
# the archive.
|
2021-07-25 04:52:13 +00:00
|
|
|
my $output_dir = '.';
|
2021-07-25 05:16:56 +00:00
|
|
|
my $test;
|
2021-07-25 04:52:13 +00:00
|
|
|
my $verbose;
|
|
|
|
GetOptions( "output-dir=s" => \$output_dir,
|
2021-07-25 05:16:56 +00:00
|
|
|
"test" => \$test,
|
2021-07-25 04:52:13 +00:00
|
|
|
"verbose" => \$verbose )
|
|
|
|
or die "Error in command line arguments";
|
|
|
|
|
2021-07-25 04:46:08 +00:00
|
|
|
|
|
|
|
sub process_components {
|
|
|
|
my $input = shift;
|
|
|
|
my $content;
|
2021-07-25 04:52:13 +00:00
|
|
|
print STDERR "processing $input\n"
|
|
|
|
if $verbose;
|
2021-07-25 04:46:08 +00:00
|
|
|
|
|
|
|
if ($input =~ /\.gz$/) {
|
|
|
|
$content = `zcat $input`;
|
|
|
|
}
|
|
|
|
elsif ($input =~ /\.xz$/) {
|
|
|
|
$content = `xzcat $input`;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die "only gz and xz suffixes are supported";
|
|
|
|
}
|
|
|
|
|
2021-07-25 06:16:44 +00:00
|
|
|
my @packages;
|
2021-07-25 04:46:08 +00:00
|
|
|
foreach my $array (Load $content) {
|
2021-07-25 05:16:56 +00:00
|
|
|
# XXX: Drop the condition once we have the required metadata
|
|
|
|
# in the archive.
|
|
|
|
if (! $test) {
|
|
|
|
next if not defined $array->{Type};
|
|
|
|
next if $array->{Type} ne 'firmware';
|
|
|
|
}
|
2021-07-25 04:46:08 +00:00
|
|
|
next if not defined $array->{Provides};
|
|
|
|
next if not defined $array->{Provides}->{modaliases};
|
|
|
|
|
2021-07-25 04:52:13 +00:00
|
|
|
print STDERR "found modaliases entries for firmware package ", $array->{Package}, "\n"
|
|
|
|
if $verbose;
|
2021-07-25 04:46:08 +00:00
|
|
|
|
2021-07-25 05:17:50 +00:00
|
|
|
my $patterns_file = $output_dir . "/" . $array->{Package} . ".patterns";
|
2021-07-25 05:10:34 +00:00
|
|
|
printf STDERR "writing %d entries to %s\n",
|
|
|
|
(scalar @{ $array->{Provides}->{modaliases} }),
|
2021-07-25 05:17:50 +00:00
|
|
|
$patterns_file;
|
2021-07-25 04:46:08 +00:00
|
|
|
|
|
|
|
# For each alias, anchor the pattern on the left (^) and on
|
|
|
|
# the right ($), and replace each '*' with '.*':
|
2021-07-25 05:17:50 +00:00
|
|
|
write_file($patterns_file,
|
2021-07-25 04:46:08 +00:00
|
|
|
map { $a = $_; $a =~ s/[*]/.*/g; "^$a\$\n" }
|
|
|
|
@{ $array->{Provides}->{modaliases} });
|
2021-07-25 06:16:44 +00:00
|
|
|
push @packages, $array->{Package};
|
2021-07-25 04:46:08 +00:00
|
|
|
}
|
2021-07-25 06:16:44 +00:00
|
|
|
return @packages;
|
2021-07-25 04:46:08 +00:00
|
|
|
}
|
2021-07-25 06:01:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Prepare output directory:
|
|
|
|
if (! -d $output_dir) {
|
|
|
|
print STDERR "creating output directory $output_dir\n"
|
|
|
|
if $verbose;
|
|
|
|
make_path($output_dir, { verbose => $verbose });
|
|
|
|
}
|
|
|
|
|
|
|
|
write_file("$output_dir/README.txt",
|
|
|
|
"These files help Debian Installer detect helpful firmware packages (via hw-detect).\n");
|
|
|
|
|
|
|
|
# Generate a .patterns file for each firmware package found in
|
|
|
|
# Components-* files:
|
2021-07-25 06:16:44 +00:00
|
|
|
my @all_packages;
|
2021-07-25 06:01:39 +00:00
|
|
|
foreach my $component (@ARGV) {
|
2021-07-25 06:16:44 +00:00
|
|
|
my @packages = process_components($component);
|
|
|
|
push @all_packages, @packages;
|
2021-07-25 06:01:39 +00:00
|
|
|
}
|
2021-07-25 06:16:44 +00:00
|
|
|
@all_packages = sort @all_packages;
|
|
|
|
print STDERR "all firmware packages found across all components: @all_packages\n"
|
|
|
|
if $verbose;
|