]> Raphaël G. Git Repositories - acme/blobdiff - letscron
Replace encode_json and decode_json with to_json and from_json to avoid
[acme] / letscron
index b566baed5541c05608217fa909add448644418da..e315a420f8e0610a9b154fce8c198cc3f20a77e4 100755 (executable)
--- a/letscron
+++ b/letscron
@@ -1,5 +1,20 @@
 #! /usr/bin/perl
 
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Copyright (C) 2016 - 2017 Raphaël Gertz <acmepl@rapsys.eu>
+
 # Best practice
 use strict;
 use warnings;
@@ -8,8 +23,9 @@ 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);
@@ -76,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)) {
@@ -107,7 +136,7 @@ foreach (@{$config->{certificates}}) {
        }
 
        # Run letscert with args
-       my @out = capturex([0..1], './letscert', @args);
+       my @out = capturex([0..1], 'letscert', @args);
 
        # Deal with error
        if ($EXITVAL != 0) {
@@ -142,4 +171,5 @@ foreach (@{$config->{certificates}}) {
        }
 }
 
+# Exit with success
 exit EXIT_SUCCESS;