Commit 90b994b8 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Make sure the config file is not mandatory

parent c08178a6
......@@ -156,16 +156,6 @@ if (defined($optctl{'backup'}) && defined($optctl{'restore'})) {
exit 1;
}
# Check config file exists
if (!defined($optctl{'config'})) {
$optctl{'config'} = "/etc/dbackupc.conf";
}
if (! -f $optctl{'config'}) {
print(STDERR "ERROR: Configuration file '".$optctl{'config'}."' NOT found!\n");
exit 1;
}
# Make sure we only have 2 additional args
if (@ARGV > 2 || @ARGV < 2) {
print(STDERR "ERROR: Invalid number of arguments\n\n");
......@@ -183,21 +173,33 @@ if (! -d $ARGV[1]) {
exit 1;
}
# Use config file, ignore case
tie my %inifile, 'Config::IniFiles', (
-file => $optctl{'config'},
-nocase => 1
) or die "Failed to open config file '".$optctl{'config'}."': ".join("\n",@Config::IniFiles::errors);
# Check if we actually have something...
if (defined($inifile{'backup'})) {
# Loop with config items
foreach my $item (keys %{$inifile{'backup'}}) {
$config{$item} = $inifile{'backup'}{$item};
# If backup file is specified and it does not exist, throw an error
if (defined($optctl{'config'}) && ! -f $optctl{'config'}) {
print(STDERR "ERROR: Configuration file '".$optctl{'config'}."' NOT found!\n");
exit 1;
}
# Check config file was specified, if not set default
my $configFile;
if (!defined($configFile = $optctl{'config'})) {
$configFile = "/etc/dbackup.conf";
}
# If we have a config file, read it in
if (-f $configFile) {
# Use config file, ignore case
tie my %inifile, 'Config::IniFiles', (
-file => $optctl{'config'},
-nocase => 1
) or die "Failed to open config file '".$optctl{'config'}."': ".join("\n",@Config::IniFiles::errors);
# Check if we actually have something...
if (defined($inifile{'backup'})) {
# Loop with config items
foreach my $item (keys %{$inifile{'backup'}}) {
$config{$item} = $inifile{'backup'}{$item};
}
}
}
#
# Process config
#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment