1st
This commit is contained in:
parent
8856d187ba
commit
c53c1299eb
6 changed files with 159 additions and 0 deletions
41
save-add-deduplicate.sh
Executable file
41
save-add-deduplicate.sh
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/perl -p
|
||||
# combine ipset save files setting max per a flat file of ipset per row in the form NAME MAX
|
||||
#
|
||||
#(c)2026 Corwin Brust <corwin@bru.st>
|
||||
# You may use this program under the terms of the GNU Public License version three (3) or, at your option, any later version of that license. (GPLv3+)
|
||||
#
|
||||
# Input is expected on stdin in the same format as output by ipset save
|
||||
#
|
||||
|
||||
BEGIN {
|
||||
my $SET_COUNTS = @ARGV
|
||||
? shift
|
||||
: q(max-counts.txt);
|
||||
|
||||
open my$FH,q(<),$SET_COUNTS
|
||||
or die $!;
|
||||
|
||||
while(<$FH>) {
|
||||
chomp;
|
||||
my($k,$v)=split;
|
||||
$m{$k}=$v if $k and $v
|
||||
}
|
||||
}
|
||||
|
||||
if(/^create (\S+)/) {
|
||||
if(exists $h{$1}) {
|
||||
$_ = '';
|
||||
} elsif(exists $m{$1}) {
|
||||
$h{$1} = $1;
|
||||
$n = $m{$1};
|
||||
s/^(create (\S+).*?hashsize) \d+ (.*)$/$1 $n $3/
|
||||
}
|
||||
else {
|
||||
$_ = ''; # skip create when no max defined
|
||||
}
|
||||
}
|
||||
elsif(/^add (\S+)/)
|
||||
{
|
||||
$_ = '' unless exists $m{$1};
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue