]> git.ipfire.org Git - thirdparty/xtables-addons.git/commitdiff
geoip: add -D option to geoip_build_dir.pl
authorJan Engelhardt <jengelh@medozas.de>
Sat, 24 Jul 2010 09:18:24 +0000 (11:18 +0200)
committerJan Engelhardt <jengelh@medozas.de>
Sat, 24 Jul 2010 09:22:37 +0000 (11:22 +0200)
This option allows to specify a particular output directory. This help
Makefiles in that they do not need to use cd.

geoip/geoip_build_db.pl

index 435593e3549d8091155d034096448fe81a8c502f..511f48e88d1a8a5e749db984b48ee590c0dc2117 100755 (executable)
@@ -14,9 +14,18 @@ my %country;
 my %names;
 my $csv = Text::CSV_XS->new({binary => 0, eol => $/}); # or Text::CSV
 my $mode = "VV";
+my $target_dir = ".";
 
 &Getopt::Long::Configure(qw(bundling));
-&GetOptions("b" => sub { $mode = "NN"; });
+&GetOptions(
+       "D=s" => \$target_dir,
+       "b"   => sub { $mode = "NN"; },
+);
+
+if (!-d $target_dir) {
+       print STDERR "Target directory $target_dir does not exist.\n";
+       exit 1;
+}
 
 while (my $row = $csv->getline(*ARGV)) {
        if (!defined($country{$row->[4]})) {
@@ -37,7 +46,7 @@ foreach my $iso_code (sort keys %country) {
                scalar(@{$country{$iso_code}}),
                $iso_code, $names{$iso_code};
 
-       open(my $fh, ">".uc($iso_code).".iv0");
+       open(my $fh, "> $target_dir/".uc($iso_code).".iv0");
        foreach my $range (@{$country{$iso_code}}) {
                print $fh pack($mode, $range->[0], $range->[1]);
        }