From 23ab67a099e32a9ee8c0700fe46bc43680a60721 Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Tue, 3 Sep 2013 09:58:17 +0200 Subject: [PATCH 1/1] Make configuration file configurable. Add --conffile option to all scripts to overrride standard config file location etc/newsstats.conf. Signed-off-by: Thomas Hochstein --- bin/feedlog.pl | 13 +++++++++---- bin/gatherstats.pl | 13 +++++++++---- bin/groupstats.pl | 13 +++++++++---- install/install.pl | 21 +++++++++++++-------- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/bin/feedlog.pl b/bin/feedlog.pl index 7c64cab..bbfd814 100755 --- a/bin/feedlog.pl +++ b/bin/feedlog.pl @@ -69,14 +69,15 @@ sub PrepareDB { ################################# Main program ################################# ### read commandline options -my ($OptDebug,$OptQuiet); +my ($OptDebug,$OptQuiet,$OptConfFile); GetOptions ('d|debug!' => \$OptDebug, 'q|test!' => \$OptQuiet, + 'conffile=s' => \$OptConfFile, 'h|help' => \&ShowPOD, 'V|version' => \&ShowVersion) or exit 1; ### read configuration -my %Conf = %{ReadConfig('')}; +my %Conf = %{ReadConfig($OptConfFile)}; ### init syslog openlog($0, 'nofatal,pid', LOG_NEWS); @@ -130,7 +131,7 @@ while (<>) { }; }; $DBQuery->finish; - + warn sprintf("-----\nDay: %s\nDate: %s\nMID: %s\nTS: %s\nToken: %s\n". "Size: %s\nPeer: %s\nPath: %s\nNewsgroups: %s\nHeaders: %s\n", $Day, $Date, $Mid, $Timestamp, $Token, $Size, $Peer, $Path, @@ -152,7 +153,7 @@ feedlog - log data from an INN feed to a database =head1 SYNOPSIS -B [B<-Vhdq>] +B [B<-Vhdq>] [--conffile I] =head1 REQUIREMENTS @@ -198,6 +199,10 @@ find that information most probably in your B F file. Suppress logging to syslog. +=item B<--conffile> I + +Load configuration from I instead of F. + =back =head1 INSTALLATION diff --git a/bin/gatherstats.pl b/bin/gatherstats.pl index 92d0545..6096417 100755 --- a/bin/gatherstats.pl +++ b/bin/gatherstats.pl @@ -38,7 +38,7 @@ my %LegalStats; ### read commandline options my ($OptCheckgroupsFile,$OptClientsDB,$OptDebug,$OptGroupsDB,$OptTLH, - $OptHostsDB,$OptMonth,$OptRawDB,$OptStatsType,$OptTest); + $OptHostsDB,$OptMonth,$OptRawDB,$OptStatsType,$OptTest,$OptConfFile); GetOptions ('c|checkgroups=s' => \$OptCheckgroupsFile, 'clientsdb=s' => \$OptClientsDB, 'd|debug!' => \$OptDebug, @@ -49,11 +49,12 @@ GetOptions ('c|checkgroups=s' => \$OptCheckgroupsFile, 'rawdb=s' => \$OptRawDB, 's|stats=s' => \$OptStatsType, 't|test!' => \$OptTest, + 'conffile=s' => \$OptConfFile, 'h|help' => \&ShowPOD, 'V|version' => \&ShowVersion) or exit 1; ### read configuration -my %Conf = %{ReadConfig('')}; +my %Conf = %{ReadConfig($OptConfFile)}; ### override configuration via commandline options my %ConfOverride; @@ -161,7 +162,7 @@ foreach my $Month (&ListMonth($Period)) { } }; }; - + # delete old data for that month if (!$OptTest) { $DBQuery = $DBHandle->do(sprintf("DELETE FROM %s.%s WHERE month = ?", @@ -207,7 +208,7 @@ gatherstats - process statistical data from a raw source =head1 SYNOPSIS -B [B<-Vhdt>] [B<-m> I | I] [B<-s> I] [B<-c> I]] [B<--hierarchy> I] [B<--rawdb> I] [B<-groupsdb> I] [B<--clientsdb> I] [B<--hostsdb> I] +B [B<-Vhdt>] [B<-m> I | I] [B<-s> I] [B<-c> I]] [B<--hierarchy> I] [B<--rawdb> I] [B<-groupsdb> I] [B<--clientsdb> I] [B<--hostsdb> I] [--conffile I] =head1 REQUIREMENTS @@ -340,6 +341,10 @@ Override I from F. Override I from F. +=item B<--conffile> I + +Load configuration from I instead of F. + =back =head1 INSTALLATION diff --git a/bin/groupstats.pl b/bin/groupstats.pl index fc13934..7a3f7e4 100755 --- a/bin/groupstats.pl +++ b/bin/groupstats.pl @@ -32,7 +32,7 @@ Getopt::Long::config ('bundling'); ### read commandline options my ($OptBoundType,$OptCaptions,$OptCheckgroupsFile,$OptComments, $OptFileTemplate,$OptFormat,$OptGroupBy,$OptGroupsDB,$LowBound,$OptMonth, - $OptNewsgroups,$OptOrderBy,$OptReportType,$OptSums,$UppBound); + $OptNewsgroups,$OptOrderBy,$OptReportType,$OptSums,$UppBound,$OptConfFile); GetOptions ('b|boundary=s' => \$OptBoundType, 'c|captions!' => \$OptCaptions, 'checkgroups=s' => \$OptCheckgroupsFile, @@ -48,6 +48,7 @@ GetOptions ('b|boundary=s' => \$OptBoundType, 'r|report=s' => \$OptReportType, 's|sums!' => \$OptSums, 'u|upper=i' => \$UppBound, + 'conffile=s' => \$OptConfFile, 'h|help' => \&ShowPOD, 'V|version' => \&ShowVersion) or exit 1; # parse parameters @@ -82,7 +83,7 @@ if ($OptReportType) { my $ValidGroups = &ReadGroupList($OptCheckgroupsFile) if $OptCheckgroupsFile; ### read configuration -my %Conf = %{ReadConfig('')}; +my %Conf = %{ReadConfig($OptConfFile)}; ### override configuration via commandline options my %ConfOverride; @@ -245,7 +246,7 @@ if ($OptCaptions && $OptComments) { ($OptOrderBy and $OptOrderBy =~ /posting/i) ? 'by number of postings ' : '', ($OptOrderBy and $OptOrderBy =~ /-?desc$/i) ? 'descending' : 'ascending'); } - + # output data &OutputData($OptFormat,$OptComments,$GroupBy,$Precision, $OptCheckgroupsFile ? $ValidGroups : '', @@ -264,7 +265,7 @@ groupstats - create reports on newsgroup usage =head1 SYNOPSIS -B [B<-Vhcs> B<--comments>] [B<-m> I[:I] | I] [B<-n> I] [B<--checkgroups> I] [B<-r> I] [B<-l> I] [B<-u> I] [B<-b> I] [B<-g> I] [B<-o> I] [B<-f> I] [B<--filetemplate> I] [B<--groupsdb> I] +B [B<-Vhcs> B<--comments>] [B<-m> I[:I] | I] [B<-n> I] [B<--checkgroups> I] [B<-r> I] [B<-l> I] [B<-u> I] [B<-b> I] [B<-g> I] [B<-o> I] [B<-f> I] [B<--filetemplate> I] [B<--groupsdb> I] [--conffile I] =head1 REQUIREMENTS @@ -593,6 +594,10 @@ B<--nocomments> is enforced, see above. Override I from F. +=item B<--conffile> I + +Load configuration from I instead of F. + =back =head1 INSTALLATION diff --git a/install/install.pl b/install/install.pl index 1ef21fb..12cc8ec 100755 --- a/install/install.pl +++ b/install/install.pl @@ -31,8 +31,9 @@ Getopt::Long::config ('bundling'); ################################# Main program ################################# ### read commandline options -my ($OptUpdate); +my ($OptUpdate,$OptConfFile); GetOptions ('u|update=s' => \$OptUpdate, + 'conffile=s' => \$OptConfFile, 'h|help' => \&ShowPOD, 'V|version' => \&ShowVersion) or exit 1; @@ -42,7 +43,7 @@ my $Path = cwd(); ### read configuration print("Reading configuration.\n"); -my %Conf = %{ReadConfig('')}; +my %Conf = %{ReadConfig($OptConfFile)}; ##### -------------------------------------------------------------------------- ##### Database table definitions @@ -53,9 +54,9 @@ CREATE DATABASE IF NOT EXISTS `$Conf{'DBDatabase'}` DEFAULT CHARSET=utf8; SQLDB my %DBCreate = ('DBTableRaw' => < <prepare($DBCreate); $DBQuery->execute() or &Bleat(2, sprintf("Can't create database %s: %s%\n", $Conf{'DBDatabase'}, $DBI::errstr)); - + printf("Database table %s created succesfully.\n",$Conf{'DBDatabase'}); $DBHandle->disconnect; }; @@ -255,7 +256,7 @@ install - installation script =head1 SYNOPSIS -B [B<-Vh> [--update I] +B [B<-Vh> [--update I] [--conffile I] =head1 REQUIREMENTS @@ -288,6 +289,10 @@ Print this man page and exit. Don't do a fresh install, but update from I. +=item B<--conffile> I + +Load configuration from I instead of F. + =back =head1 FILES -- 2.20.1