Auto-create main config when adding first remote via WHM
gniza backup requires /etc/gniza/gniza.conf to exist. The WHM plugin only created remote configs in remotes.d/ but not the main config, causing "Config file not found" errors. Now creates it with defaults when adding a remote if it doesn't exist. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -258,6 +258,9 @@ sub handle_add {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!@errors) {
|
if (!@errors) {
|
||||||
|
# Ensure main config exists (gniza backup requires it)
|
||||||
|
_ensure_main_config();
|
||||||
|
|
||||||
# Copy example template then write values
|
# Copy example template then write values
|
||||||
my $dest = GnizaWHM::UI::remote_conf_path($name);
|
my $dest = GnizaWHM::UI::remote_conf_path($name);
|
||||||
my $example = GnizaWHM::UI::remote_example_path();
|
my $example = GnizaWHM::UI::remote_example_path();
|
||||||
@@ -792,3 +795,36 @@ sub _uri_escape {
|
|||||||
$str =~ s/([^A-Za-z0-9._~-])/sprintf("%%%02X", ord($1))/ge;
|
$str =~ s/([^A-Za-z0-9._~-])/sprintf("%%%02X", ord($1))/ge;
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub _ensure_main_config {
|
||||||
|
my $config_file = '/etc/gniza/gniza.conf';
|
||||||
|
return if -f $config_file;
|
||||||
|
|
||||||
|
# Create dirs
|
||||||
|
for my $dir ('/etc/gniza', '/etc/gniza/remotes.d', '/etc/gniza/schedules.d', '/var/log/gniza') {
|
||||||
|
mkdir $dir unless -d $dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Copy example or write defaults
|
||||||
|
my $example = '/usr/local/gniza/etc/gniza.conf.example';
|
||||||
|
if (-f $example) {
|
||||||
|
File::Copy::copy($example, $config_file);
|
||||||
|
} else {
|
||||||
|
if (open my $fh, '>', $config_file) {
|
||||||
|
print $fh qq{# gniza configuration — auto-created by WHM plugin\n};
|
||||||
|
print $fh qq{TEMP_DIR="/usr/local/gniza/workdir"\n};
|
||||||
|
print $fh qq{INCLUDE_ACCOUNTS=""\n};
|
||||||
|
print $fh qq{EXCLUDE_ACCOUNTS="nobody"\n};
|
||||||
|
print $fh qq{LOG_DIR="/var/log/gniza"\n};
|
||||||
|
print $fh qq{LOG_LEVEL="info"\n};
|
||||||
|
print $fh qq{LOG_RETAIN=90\n};
|
||||||
|
print $fh qq{NOTIFY_EMAIL=""\n};
|
||||||
|
print $fh qq{NOTIFY_ON="failure"\n};
|
||||||
|
print $fh qq{LOCK_FILE="/var/run/gniza.lock"\n};
|
||||||
|
print $fh qq{SSH_TIMEOUT=30\n};
|
||||||
|
print $fh qq{SSH_RETRIES=3\n};
|
||||||
|
print $fh qq{RSYNC_EXTRA_OPTS=""\n};
|
||||||
|
close $fh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user