about summary refs log tree commit diff stats
path: root/leo.pl
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-08-27 14:25:48 +0530
committerAndinus <andinus@nand.sh>2020-08-27 14:25:48 +0530
commit18c8216959dd817d4b6f0971773174fb6e937af0 (patch)
tree82dd2db5746a7ae03ee6155060ef1d6b44221215 /leo.pl
parent6c5aea0ee37a25ea289d44850d3dc37133f32cdf (diff)
downloadleo-18c8216959dd817d4b6f0971773174fb6e937af0.tar.gz
Add gpg2 function to Encrypt/Sign archives
Diffstat (limited to 'leo.pl')
-rwxr-xr-xleo.pl26
1 files changed, 21 insertions, 5 deletions
diff --git a/leo.pl b/leo.pl
index bdd3f3d..4790da5 100755
--- a/leo.pl
+++ b/leo.pl
@@ -57,8 +57,8 @@ sub archive {
         @archive_paths = @_;
     }
 
-    say "Archive file: $tar_file";
-    warn "$tar_file exists, might overwrite.\n" if -e $tar_file;
+    say "Archive: $tar_file";
+    warn "[WARN] $tar_file exists, might overwrite.\n" if -e $tar_file;
     print "\n";
 
     tar_create($tar_file, @_);
@@ -69,7 +69,22 @@ sub archive {
         : say path($_)->absolute($cwd), " archived."
         foreach @archive_paths;
 
-    print "\n" and tar_list($tar_file) if $options{verbose};
+    tar_list($tar_file) if $options{verbose};
+    encrypt_sign($tar_file) if $options{encrypt} or $options{sign};
+}
+
+# Encrypt, Sign archives.
+sub encrypt_sign() {
+    my $file = shift @_;
+    my @options = ("--recipient", $gpg_fingerprint);
+    push @options, "--encrypt" if $options{encrypt};
+    push @options, "--sign" if $options{sign};
+    push @options, "--verbose" if $options{verbose};
+
+    say "\nEncrypt/Sign: $file";
+    run3 ["gpg2", "--yes", "-o", "$file.gpg", @options, $file];
+    warn "[WARN] $file.gpg exists, might overwrite.\n" if -e "$file.gpg";
+    say "\nOutput: $file.gpg";
 }
 
 sub HelpMessage {
@@ -90,7 +105,8 @@ Options:
     --encrypt
         Encrypt files with $gpg_fingerprint
     --sign
-        Sign files with $gpg_fingerprint};
+        Sign files with $gpg_fingerprint
+    --verbose};
 }
 
 if ( $ARGV[0] and $dispatch{ $ARGV[0] } ) {
@@ -102,7 +118,7 @@ if ( $ARGV[0] and $dispatch{ $ARGV[0] } ) {
     die say "leo: no such option\n";
 }
 
-sub tar_create { run3 ["/bin/tar" , "cf", @_]; }
+sub tar_create { run3 ["/bin/tar", "cf", @_]; }
 sub tar_list { run3 ["/bin/tar", "tvf", @_]; }
 
 sub ymd {