]> Raphaƫl G. Git Repositories - acme/blobdiff - letscron
Fix config generation
[acme] / letscron
index 2a68110a0772a63152a9d9548cd0c4412e773b78..9a9635503422d0efa381415f2e9f7c5a09f35281 100755 (executable)
--- a/letscron
+++ b/letscron
@@ -23,14 +23,15 @@ use warnings;
 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);
@@ -68,7 +69,7 @@ unless (
                ! 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;
 }
 
@@ -91,6 +92,19 @@ foreach (@{$config->{certificates}}) {
                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)) {