summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRich Megginson <rmeggins@redhat.com>2009-02-24 16:57:45 +0000
committerRich Megginson <rmeggins@redhat.com>2009-02-24 16:57:45 +0000
commitdb2a098b97aaca733395822990cb7574e96e9135 (patch)
tree0701144b6ab7fae4d3afa06142abc0300f6ec122
parentc1b510f60a509e54eff163003c292ebb1d94fc1a (diff)
downloadds-db2a098b97aaca733395822990cb7574e96e9135.tar.gz
ds-db2a098b97aaca733395822990cb7574e96e9135.tar.xz
ds-db2a098b97aaca733395822990cb7574e96e9135.zip
Resolves: bug 486474
Bug Description: overriding arguments to setup causes setup to fail Reviewed by: ulf.weltman, nkinder (Thanks!) Fix Description: Parameters specified on the command line should override and replace (not add to) any parameters specified in a given .inf file. I refactored the code a little too - I moved the argv processing into the Inf module out of the Setup and Migration modules. The code will first process the args and store the values in a temporary hash ref. Then it will process the temp hash ref, replacing the values in the main inf with the values from the hash. Platforms tested: RHEL4 Flag Day: no Doc impact: no
-rw-r--r--ldap/admin/src/scripts/Inf.pm54
-rw-r--r--ldap/admin/src/scripts/Migration.pm.in11
-rw-r--r--ldap/admin/src/scripts/Setup.pm.in27
3 files changed, 60 insertions, 32 deletions
diff --git a/ldap/admin/src/scripts/Inf.pm b/ldap/admin/src/scripts/Inf.pm
index 4d413630..0ac11a41 100644
--- a/ldap/admin/src/scripts/Inf.pm
+++ b/ldap/admin/src/scripts/Inf.pm
@@ -192,6 +192,60 @@ sub write {
close INF;
}
+sub updateFromArgs {
+ my $self = shift;
+ my $argsinf = {}; # tmp for args read in
+
+ if (!@_) {
+ return 1; # no args - just return
+ }
+
+ # read args into temp inf
+ for (@_) {
+ if (/^([\w_-]+)\.([\w_-]+)=(.*)$/) { # e.g. section.param=value
+ my $sec = $1;
+ my $parm = $2;
+ my $val = $3;
+ # a single value is just a single scalar
+ # multiple values are represented by an array ref
+ if (exists($argsinf->{$sec}->{$parm})) {
+ if (!ref($argsinf->{$sec}->{$parm})) {
+ # convert single scalar to array ref
+ my $ary = [$argsinf->{$sec}->{$parm}];
+ $argsinf->{$sec}->{$parm} = $ary;
+ }
+ # just push the new value
+ push @{$argsinf->{$sec}->{$parm}}, $val;
+ } else {
+ # single value
+ $argsinf->{$sec}->{$parm} = $val;
+ }
+ } else { # error
+ print STDERR "Error: unknown command line option $_\n";
+ return;
+ }
+ }
+
+ # no args read - just return true
+ if (!$argsinf || !%{$argsinf}) {
+ return 1;
+ }
+
+ # override inf with vals read from args
+ while (my ($name, $sec) = each %{$argsinf}) {
+ if (ref($sec) eq 'HASH') {
+ for my $key (keys %{$sec}) {
+ if (defined($sec->{$key})) {
+ my $val = $sec->{$key};
+ $self->{$name}->{$key} = $val;
+ }
+ }
+ }
+ }
+
+ return 1;
+}
+
#############################################################################
# Mandatory TRUE return value.
#
diff --git a/ldap/admin/src/scripts/Migration.pm.in b/ldap/admin/src/scripts/Migration.pm.in
index 7256d2a6..86eb6fd1 100644
--- a/ldap/admin/src/scripts/Migration.pm.in
+++ b/ldap/admin/src/scripts/Migration.pm.in
@@ -232,14 +232,9 @@ sub init {
# see if user passed in default inf values - also, command line
# arguments override those passed in via an inf file - this
# allows the reuse of .inf files with some parameters overridden
- for (@ARGV) {
- if (/^([\w_-]+)\.([\w_-]+)=(.*)$/) { # e.g. section.param=value
- $self->{inf}->{$1}->{$2} = $3;
- } else { # error
- print STDERR "Error: unknown command line option $_\n";
- usage();
- exit 1;
- }
+ if (!$self->{inf}->updateFromArgs(@ARGV)) {
+ HelpMessage();
+ exit 1;
}
# this is the base config directory - the directory containing
diff --git a/ldap/admin/src/scripts/Setup.pm.in b/ldap/admin/src/scripts/Setup.pm.in
index 814a6a84..7ad57c1f 100644
--- a/ldap/admin/src/scripts/Setup.pm.in
+++ b/ldap/admin/src/scripts/Setup.pm.in
@@ -161,30 +161,9 @@ sub init {
# see if user passed in default inf values - also, command line
# arguments override those passed in via an inf file - this
# allows the reuse of .inf files with some parameters overridden
- for (@ARGV) {
- if (/^([\w_-]+)\.([\w_-]+)=(.*)$/) { # e.g. section.param=value
- my $sec = $1;
- my $parm = $2;
- my $val = $3;
- # a single value is just a single scalar
- # multiple values are represented by an array ref
- if (exists($self->{inf}->{$sec}->{$parm})) {
- if (!ref($self->{inf}->{$sec}->{$parm})) {
- # convert single scalar to array ref
- my $ary = [$self->{inf}->{$sec}->{$parm}];
- $self->{inf}->{$sec}->{$parm} = $ary;
- }
- # just push the new value
- push @{$self->{inf}->{$sec}->{$parm}}, $val;
- } else {
- # single value
- $self->{inf}->{$sec}->{$parm} = $val;
- }
- } else { # error
- print STDERR "Error: unknown command line option $_\n";
- HelpMessage();
- exit 1;
- }
+ if (!$self->{inf}->updateFromArgs(@ARGV)) {
+ HelpMessage();
+ exit 1;
}
# this is the base config directory - the directory containing