Bug#638295: debmirror: support alternative configuration files

June 25th, 2012 - 04:50 am ET by Matthias Schmitz | Report spam


Hi Joey, hi everyone,

i also need to specify an alternative configuration file to debmirror
because i need to mirror Debian and Ubuntu on the same host.
The attached patch adds the command line switch "--config-file=".

Now i run debmirror like this:
debmirror --config-file=/etc/debmirror-ubuntu.conf
debmirror --config-file=/etc/debmirror-debian.conf

Please review the patch and include if it is fine.

best wishes,
Matthias


filename01-Add-switch-to-specify-configuration-file-at-command-.patch

From 7a4f928a0c221e9a8003440cd57216d6bafcdfea Mon Sep 17 00:00:00 2001
From: Matthias Schmitz <matthias@sigxcpu.org>
Date: Mon, 25 Jun 2012 10:32:01 +0200
Subject: [PATCH] Add switch to specify configuration file at command line.

* Add command line switch --config-file= to allow specification of
alternate configuration file.

debmirror | 19 +++++++++++++++-
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/debmirror b/debmirror
index ccb4fbd..9f6d687 100755
a/debmirror
+++ b/debmirror
@@ -575,14 +575,11 @@ our $debmarshal=0;
our $slow_cpu=0;
our $check_gpg=1;
our $new_mirror=0;
+our $config_file=undef;
my @errlog;
my $HOME;
($HOME = $ENV{'HOME'}) or die "HOME not defined in environment!";

-# Load in config files
-require "/etc/debmirror.conf" if -r "/etc/debmirror.conf";
-require "$HOME/.debmirror.conf" if -r "$HOME/.debmirror.conf";
-
# This hash contains the releases to mirror. If both codename and suite can be
# determined from the Release file, the codename is used in the key. If not,
# it can also be a suite (or whatever was requested by the user).
@@ -674,10 +671,24 @@ GetOptions('debug' => \$debug,
'debmarshal' => \$debmarshal,
'slow-cpu' => \$slow_cpu,
'help' => \$help,
+ 'config-file=s' => \$config_file,
) or usage;
usage if $help;
usage("invalid number of arguments") if $ARGV[1];

+# Load in config files
+if ( defined $config_file ) {
+ if ( -r $config_file ) {
+ require $config_file;
+ } else {
+ die "Cannot open config file $config_file.";
+ }
+} else {
+ require "/etc/debmirror.conf" if -r "/etc/debmirror.conf";
+ require "$HOME/.debmirror.conf" if -r "$HOME/.debmirror.conf";
+}
+
+
# This parameter is so important that it is the only required parameter,
# unless specified in a configuration file.
$mirrordir = shift if $ARGV[0];
1.7.10








To UNSUBSCRIBE, email to debian-bugs-dist-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
email Follow the discussionReplies 4 repliesReplies Make a reply

Similar topics

Replies

#1 Joey Hess
June 25th, 2012 - 10:50 am ET | Report spam

Matthias Schmitz wrote:
-# Load in config files
@@ -674,10 +671,24 @@ GetOptions('debug' => \$debug,
+# Load in config files



This patch changes behavior in an important way: where before
command-line options overrode config file settings, now the config file
is loaded after option parsing and overrides options.

see shy jo






To UNSUBSCRIBE, email to
with a subject of "unsubscribe". Trouble? Contact
Replies Reply to this message
#2 Matthias Schmitz
June 25th, 2012 - 11:50 am ET | Report spam

Hi Joey, hi *,

Am Mon, 25 Jun 2012 10:43:02 -0400
schrieb Joey Hess :

Matthias Schmitz wrote:
> -# Load in config files
> @@ -674,10 +671,24 @@ GetOptions('debug' =>
> \$debug, +# Load in config files

This patch changes behavior in an important way: where before
command-line options overrode config file settings, now the config
file is loaded after option parsing and overrides options.


arg, you are right. Is it ok to leave the old behavior (cli switch
override configuration file setting) and add a warning to the


Best wishes,
Matthias






To UNSUBSCRIBE, email to
with a subject of "unsubscribe". Trouble? Contact
Replies Reply to this message
#3 Joey Hess
June 25th, 2012 - 12:20 pm ET | Report spam

Matthias Schmitz wrote:
arg, you are right. Is it ok to leave the old behavior (cli switch
override configuration file setting) and add a warning to the



The --config-file could *add* the specified file. Keep it reading
debmirror.conf before options, and then it could be used for setting
defaults that could be overridden by options and --config-file

see shy jo






To UNSUBSCRIBE, email to
with a subject of "unsubscribe". Trouble? Contact
Replies Reply to this message
#4 Matthias Schmitz
June 25th, 2012 - 03:10 pm ET | Report spam


Hi Joey, hi *,

Am Mon, 25 Jun 2012 12:13:10 -0400
schrieb Joey Hess :

Matthias Schmitz wrote:
> arg, you are right. Is it ok to leave the old behavior (cli switch
> override configuration file setting) and add a warning to the

The --config-file could *add* the specified file. Keep it reading
debmirror.conf before options, and then it could be used for setting
defaults that could be overridden by options and --config-file


thanks for the quick reply :-).
With the attached patch the default behavior is untouched (require
debmirror.conf before cli switches) and the file read with --config-file
is additional. But it still overrides all cli switches.

Best wishes,
Matthias

filename01-Add-switch-to-specify-an-additional-configuration-fi.patch

From e2929b2c06c47b9df0c383c5ebcd84312b47fa5b Mon Sep 17 00:00:00 2001
From: Matthias Schmitz
Date: Mon, 25 Jun 2012 20:41:21 +0200
Subject: [PATCH] Add switch to specify an additional configuration file at
command line.


debmirror | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/debmirror b/debmirror
index ccb4fbd..f8b7da2 100755
a/debmirror
+++ b/debmirror
@@ -412,6 +412,14 @@ debmirror cleanup is disabled when this flag is specified.
Separate pool and snapshot cleanup utilities are available at
http://code.google.com/p/debmarshal...epository2

+=item B<--config-file>
+
+Specify an additional configuration file. By default debmirror reads
+/etc/debmirror.conf and ~/.debmirror.conf (see section FILES).
+
+WARNING: All parameters set in a configuration file specified with
+--config-file cannot be overridden by a command line switch.
+
=back

=head1 USING DEBMIRROR
@@ -575,6 +583,7 @@ our $debmarshal=0;
our $slow_cpu=0;
our $check_gpg=1;
our $new_mirror=0;
+our $config_file=undef;
my @errlog;
my $HOME;
($HOME = $ENV{'HOME'}) or die "HOME not defined in environment!";
@@ -674,10 +683,20 @@ GetOptions('debug' => \$debug,
'debmarshal' => \$debmarshal,
'slow-cpu' => \$slow_cpu,
'help' => \$help,
+ 'config-file=s' => \$config_file,
) or usage;
usage if $help;
usage("invalid number of arguments") if $ARGV[1];

+# Load in additional config file
+if ( defined $config_file ) {
+ if ( -r $config_file ) {
+ require $config_file;
+ } else {
+ die "Cannot open config file $config_file.";
+ }
+}
+
# This parameter is so important that it is the only required parameter,
# unless specified in a configuration file.
$mirrordir = shift if $ARGV[0];
1.7.10








To UNSUBSCRIBE, email to
with a subject of "unsubscribe". Trouble? Contact
email Follow the discussion Replies Reply to this message
Help Create a new topicReplies Make a reply
Search Make your own search