summaryrefslogtreecommitdiffstats
path: root/update-ldetect-lst
blob: beabe0696e995b34b4b298befb3879ad49bf0eb0 (plain)
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
#!/usr/bin/perl

my $dir = '/usr/share/ldetect-lst';
my @files = qw(pcitable usbtable isatable pcmciatable dmitable);

unlink("$dir/$_", "$dir/$_.gz") foreach @files;

$ARGV[0] eq '--clean' and exit 0;

foreach (@files) {
    my $d = "$dir/$_.d";
    -d $d or next;
    my @l = sort glob("$d/*.lst");
    my @l_gz = sort glob("$d/*.lst.gz");
    @l || @l_gz or next;
    if (@l == 0 && @l_gz == 1) {
	link $l_gz[0], "$dir/$_.gz";
    } else {
	open(my $OUT, "| gzip -9 > $dir/$_.gz");
	push @l, map { "gzip -dc $_ |" } @l_gz;
	foreach (@l) {
	    open(my $IN, $_) or next;
	    print $OUT $_ foreach <$IN>;
	}
    }
}