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
|
#! /usr/bin/perl -wnp
##
## This script removes lines that are for foreign architectures. If it
## finds a line prefixed with [arch1 arch2 ...], it will check -
## with dpkg-architecture - if we match any of the wildcards. If we
## match any of it, the line will be kept, otherwise eliminated.
BEGIN {
sub arch_filter {
my $arch = $_[0];
my $check_arch = $arch;
if ($arch =~ /^!/) {
$check_arch =~ s/^!//;
}
`dpkg-architecture -i${check_arch} 2>/dev/null`;
return TRUE if $? == 0;
return FALSE;
}
sub validate_arches {
my $p = 0;
my $n = 0;
foreach my $arch (@_) {
if ($arch =~ /^!/) {
$p++;
} else {
$n++;
}
}
if ($n > 0 && $p > 0) {
print STDERR "ERROR: Positive and negative arch ".
"filters cannot be mixed!\n";
exit (1);
}
}
}
if (/(\s+\[([^\]]*)\])$/ || /^(\[([^\]]*)\][ \t]+)/) {
my ($spec, $inner) = ($1, $2);
my @archlist = split (/\s+/, $inner);
my $valid = FALSE;
validate_arches(@archlist);
for my $arch (@archlist) {
$valid = TRUE if (arch_filter($arch) eq TRUE);
}
$valid = ($valid eq TRUE) ? FALSE : TRUE if ($inner =~ /!/);
if ($valid eq TRUE) {
s/\Q$spec\E//;
} else {
$_ = "";
}
}
|