aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2015-04-01 21:10:11 +0300
committerSergey Poznyakoff <gray@gnu.org>2015-04-01 21:10:11 +0300
commitaa0a3f7cbd7fd1b230386f434ad472bc06f01b6e (patch)
treeceff5f76bc521497c01116232fbe31489d8de240
parent74828acdf2dcce9e66318a2852ec4473364c7458 (diff)
downloaddnstools-aa0a3f7cbd7fd1b230386f434ad472bc06f01b6e.tar.gz
dnstools-aa0a3f7cbd7fd1b230386f434ad472bc06f01b6e.tar.bz2
nsdbimport: add makefiles
-rw-r--r--Makefile2
-rw-r--r--nsdbimport/GNUmakefile2
-rw-r--r--nsdbimport/MANIFEST5
-rw-r--r--nsdbimport/Makefile.PL37
-rwxr-xr-xnsdbimport/nsdbimport22
5 files changed, 64 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 87e377f..36cc766 100644
--- a/Makefile
+++ b/Makefile
@@ -11,13 +11,13 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-SUBDIRS = dnsdbck rpsl2acl axfr2acl vhostcname renewck whoseip
+SUBDIRS = dnsdbck rpsl2acl axfr2acl vhostcname renewck whoseip nsdbimport
include Make.vars
dist:
for dir in $(SUBDIRS); do \
make -C $$dir dist; \
diff --git a/nsdbimport/GNUmakefile b/nsdbimport/GNUmakefile
new file mode 100644
index 0000000..e61b3c3
--- /dev/null
+++ b/nsdbimport/GNUmakefile
@@ -0,0 +1,2 @@
+include ../Make.vars
+include ../Make.rules
diff --git a/nsdbimport/MANIFEST b/nsdbimport/MANIFEST
new file mode 100644
index 0000000..822ea34
--- /dev/null
+++ b/nsdbimport/MANIFEST
@@ -0,0 +1,5 @@
+MANIFEST
+Makefile.PL
+inc/ExtUtils/AutoInstall.pm
+nsdbimport
+
diff --git a/nsdbimport/Makefile.PL b/nsdbimport/Makefile.PL
new file mode 100644
index 0000000..9deb44e
--- /dev/null
+++ b/nsdbimport/Makefile.PL
@@ -0,0 +1,37 @@
+# -*- perl -*-
+# Copyright (C) 2015 Sergey Poznyakoff <gray@gnu.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+use lib 'inc';
+use ExtUtils::AutoInstall (
+ -core => [
+ 'Getopt::Long' => 2.34,
+ 'Pod::Usage' => 1.51,
+ 'Pod::Man' => 2.25,
+ 'DBI' => 1.607,
+ 'String::Regexp' => 1.00
+ ]
+);
+
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+ 'NAME' => 'nsdbimport',
+ 'AUTHOR' => 'Sergey Poznyakoff <gray@gnu.org>',
+ 'ABSTRACT' => 'converts BIND zone files to SQL database',
+ 'FIRST_MAKEFILE' => 'Makefile',
+ 'VERSION' => '1.00',
+ 'EXE_FILES' => [ 'nsdbimport' ],
+);
diff --git a/nsdbimport/nsdbimport b/nsdbimport/nsdbimport
index dc93c6d..7c72f71 100755
--- a/nsdbimport/nsdbimport
+++ b/nsdbimport/nsdbimport
@@ -33,16 +33,18 @@ use constant EX_CANTCREAT => 73; # can't create (user) output file
use constant EX_CONFIG => 78; # configuration error
my $progname = basename($0); # This script name;
my $progdescr = "converts BIND zone files to SQL database";
my $debug;
my $dry_run;
+my $verbose;
my $bind_directory;
my $bind_config;
my $dbd;
my $generate_seen;
+my $record_count;
sub error {
my $msg = shift;
local %_ = @_;
print STDERR "$progname: " if defined($progname);
print STDERR "$_{prefix}: " if defined($_{prefix});
@@ -58,12 +60,18 @@ sub abend {
my $code = shift;
print STDERR "$progname: " if defined($progname);
print STDERR "@_\n";
exit $code;
}
+END {
+ if ($record_count and ($verbose or $?)) {
+ print "$progname: $record_count records processed successfully\n";
+ }
+}
+
my %config;
sub readconfig {
my ($file, $kw) = @_;
open(my $fd, "<", $file)
or abend(EX_UNAVAILABLE, "can't open configuration file $file: $!");
@@ -192,12 +200,13 @@ sub sql_query {
my ($tmpl, $rec) = @_;
my $q = query_expand($tmpl, $rec);
unless ($dry_run) {
$dbd->do($q)
or abend(EX_UNAVAILABLE, $dbd->errstr."\nFailed query: $q");
}
+ ++$record_count;
}
# generate($expr, $origin, $file, $line);
# $GENERATE start-stop[/step] lhs[{offset[,width[,type]]}] rr-type rhs[{offset[,width[,type]]}]
# http://www.zytrax.com/books/dns/ch8/generate.html
@@ -410,12 +419,13 @@ GetOptions("h" => sub {
pod2usage(-exitstatus => EX_OK, -verbose => 0);
},
"directory|C=s" => \$bind_directory,
"bind-config|from-config=s" => \$bind_config,
"origin=s" => \$origin,
"debug|d+" => \$debug,
+ "verbose|v+" => \$verbose,
"dry-run|n" => \$dry_run,
"config|c=s" => \$conffile) or exit(EX_USAGE);
++$debug if $dry_run;
unless (defined($conffile)) {
@@ -463,13 +473,13 @@ if (!$arg
}
}
$arg = 'DBI:mysql'.$arg;
$dbd = DBI->connect($arg, $config{user}, $config{password},
{ PrintError => 0, AutoCommit => 1})
- or exit(EX_UNAVAILABLE);
+ or abend(EX_UNAVAILABLE, "can't connect to the database: ".$DBI::errstr);
if (defined($bind_config)) {
abend(EX_USAGE, "extra input files") if $#ARGV >= 0;
my %files = parse_named_conf;
while (my ($file, $origin) = each %files) {
zimport($file, $origin);
@@ -490,24 +500,25 @@ __END__
nsdbimport - import data from BIND-compatible zone files to SQL database
=head1 SYNOPSIS
B<nsdbimport>
-[B<-dhn>]
+[B<-dhnv>]
[B<-C> I<DIR>]
[B<-c> I<FILE>]
[B<--bind-config=>I<FILE>]
[B<--config=>I<FILE>
[B<--debug>]
[B<--directory=>I<DIR>]
[B<--dry-run>]
[B<--from-config=>I<FILE>]
[B<--help>]
[B<--origin=>I<ZONE>]
-[B<--usage>]
+[B<--usage>]
+[B<--verbose>]
[I<ZONEFILE>...]
=head1 DESCRIPTION
Imports DNS records from zone files in BIND-compatible format into a SQL
database. The format of the database (or, more precisely, SQL statements
@@ -554,12 +565,17 @@ installed on your system.
Don't actually import data, print what would have been done instead.
=item B<--origin=>I<ZONE>
Set initial origin. Useful when processing individual files.
+=item B<-v>, B<--verbose>
+
+Verbose mode. Report count of successfully processed records at the
+end of the run.
+
=back
The following options cause the program to display informative text and
exit:
=over 4

Return to:

Send suggestions and report system problems to the System administrator.