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'})) { ...@@ -156,16 +156,6 @@ if (defined($optctl{'backup'}) && defined($optctl{'restore'})) {
exit 1; 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 # Make sure we only have 2 additional args
if (@ARGV > 2 || @ARGV < 2) { if (@ARGV > 2 || @ARGV < 2) {
print(STDERR "ERROR: Invalid number of arguments\n\n"); print(STDERR "ERROR: Invalid number of arguments\n\n");
...@@ -183,21 +173,33 @@ if (! -d $ARGV[1]) { ...@@ -183,21 +173,33 @@ if (! -d $ARGV[1]) {
exit 1; exit 1;
} }
# Use config file, ignore case # If backup file is specified and it does not exist, throw an error
tie my %inifile, 'Config::IniFiles', ( if (defined($optctl{'config'}) && ! -f $optctl{'config'}) {
-file => $optctl{'config'}, print(STDERR "ERROR: Configuration file '".$optctl{'config'}."' NOT found!\n");
-nocase => 1 exit 1;
) or die "Failed to open config file '".$optctl{'config'}."': ".join("\n",@Config::IniFiles::errors); }
# Check config file was specified, if not set default
# Check if we actually have something... my $configFile;
if (defined($inifile{'backup'})) { if (!defined($configFile = $optctl{'config'})) {
# Loop with config items $configFile = "/etc/dbackup.conf";
foreach my $item (keys %{$inifile{'backup'}}) { }
$config{$item} = $inifile{'backup'}{$item}; # 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 # Process config
# #
......
Supports Markdown
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