use filetest 'access';
# Load dependancies
-use Carp qw(carp);
+use Carp qw(carp confess);
use DateTime;
+use File::Path qw(make_path);
use File::stat qw(stat);
use File::Spec;
use File::Slurp qw(read_file write_file);
use JSON qw(decode_json);
use IPC::System::Simple qw(capturex $EXITVAL);
-use acme qw(CERT_DIR CONFIG DS KEY_DIR SERVER_CRT SERVER_KEY);
+use Acme qw(CERT_DIR CONFIG DS KEY_DIR SERVER_CRT SERVER_KEY);
# Load POSIX
use POSIX qw(strftime EXIT_SUCCESS EXIT_FAILURE);
! scalar map {unless(defined($_->{cert}) && defined($_->{key}) && defined($_->{mail}) && defined($_->{domain}) && defined($_->{domains})) {1;} else {();}} @{$config->{certificates}}
}
) {
- print 'Config file '.CONFIG.' is invalid'."\n";
+ print 'Config file '.CONFIG.' is not readable or invalid'."\n";
exit EXIT_FAILURE;
}
next;
}
+ # Check that key directory exists
+ if (! -d KEY_DIR) {
+ # Create all paths
+ make_path(KEY_DIR, {error => \my $err});
+ if (@$err) {
+ map {
+ my ($file, $msg) = %$_;
+ carp ($file eq '' ? '' : $file.': ').$msg if ($debug);
+ } @$err;
+ confess 'make_path failed';
+ }
+ }
+
# Unlink if is a symlink
if (-l KEY_DIR.DS.SERVER_KEY) {
unless(unlink(KEY_DIR.DS.SERVER_KEY)) {