From aa0a3f7cbd7fd1b230386f434ad472bc06f01b6e Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Wed, 1 Apr 2015 21:10:11 +0300 Subject: nsdbimport: add makefiles --- nsdbimport/GNUmakefile | 2 ++ nsdbimport/MANIFEST | 5 +++++ nsdbimport/Makefile.PL | 37 +++++++++++++++++++++++++++++++++++++ nsdbimport/nsdbimport | 22 +++++++++++++++++++--- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 nsdbimport/GNUmakefile create mode 100644 nsdbimport/MANIFEST create mode 100644 nsdbimport/Makefile.PL (limited to 'nsdbimport') 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 +# +# 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 . + +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 ', + '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 @@ -36,10 +36,12 @@ 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; @@ -61,6 +63,12 @@ sub abend { exit $code; } +END { + if ($record_count and ($verbose or $?)) { + print "$progname: $record_count records processed successfully\n"; + } +} + my %config; sub readconfig { @@ -195,6 +203,7 @@ sub sql_query { $dbd->do($q) or abend(EX_UNAVAILABLE, $dbd->errstr."\nFailed query: $q"); } + ++$record_count; } # generate($expr, $origin, $file, $line); @@ -413,6 +422,7 @@ GetOptions("h" => sub { "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); @@ -466,7 +476,7 @@ $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; @@ -493,7 +503,7 @@ nsdbimport - import data from BIND-compatible zone files to SQL database =head1 SYNOPSIS B -[B<-dhn>] +[B<-dhnv>] [B<-C> I] [B<-c> I] [B<--bind-config=>I] @@ -504,7 +514,8 @@ B [B<--from-config=>I] [B<--help>] [B<--origin=>I] -[B<--usage>] +[B<--usage>] +[B<--verbose>] [I...] =head1 DESCRIPTION @@ -557,6 +568,11 @@ Don't actually import data, print what would have been done instead. 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 -- cgit v1.2.1