about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-11-11 01:22:41 +0530
committerAndinus <andinus@nand.sh>2020-11-11 01:22:41 +0530
commite1ceacf5a2ad5b389377a70190b1a979f59e19b0 (patch)
tree1b387594715d3ea42168dbd71ce1369eaea438d8
parent2aa21cf7d9c689da89568ecd210a44c09e5a39ee (diff)
downloadleo-e1ceacf5a2ad5b389377a70190b1a979f59e19b0.tar.gz
Add gzip support for compressing archives v0.3.2
Archives can now be compressed by gzip(1).
-rw-r--r--README12
-rwxr-xr-xleo.pl36
-rw-r--r--share/leo.conf3
3 files changed, 39 insertions, 12 deletions
diff --git a/README b/README
index b878543..9f9e488 100644
--- a/README
+++ b/README
@@ -14,7 +14,8 @@ Table of Contents
 .. 2. Options
 ..... 1. encrypt/sign
 ..... 2. signify
-..... 3. help
+..... 3. gzip
+..... 4. help
 3. Example
 4. Demo
 5. History
@@ -80,6 +81,7 @@ with signify(1).
    encrypt  `LEO_ENCRYPT'
    sign     `LEO_SIGN'
    signify  `LEO_SIGNIFY'
+   gzip     `LEO_GZIP'
   ━━━━━━━━━━━━━━━━━━━━━━━━
 
 
@@ -104,7 +106,13 @@ with signify(1).
   `signify' will invoke `signify(1)' & the file will be signed.
 
 
-2.2.3 help
+2.2.3 gzip
+╌╌╌╌╌╌╌╌╌╌
+
+  `gzip' will compress the tar archive with `gzip(1)'.
+
+
+2.2.4 help
 ╌╌╌╌╌╌╌╌╌╌
 
   Running just `leo' will print help.
diff --git a/leo.pl b/leo.pl
index 2e9dc93..92322db 100755
--- a/leo.pl
+++ b/leo.pl
@@ -15,11 +15,12 @@ my %options = (
     encrypt => $ENV{LEO_ENCRYPT},
     sign => $ENV{LEO_SIGN},
     signify => $ENV{LEO_SIGNIFY},
+    gzip => $ENV{LEO_GZIP},
 );
 
 GetOptions(
     \%options,
-    qw{ verbose encrypt sign signify delete help }
+    qw{ verbose encrypt sign signify gzip help }
 ) or die "Error in command line arguments\n";
 
 # Configuration.
@@ -43,7 +44,7 @@ foreach my $section (sort keys $config->%*) {
     next if $section eq "_";
 
     # Set global values to local profiles.
-    foreach (qw( encrypt sign signify )) {
+    foreach (qw( encrypt sign signify gzip )) {
         $profile{$section}{$_} = $options{$_};
     }
 
@@ -51,7 +52,8 @@ foreach my $section (sort keys $config->%*) {
         # Override encrypt & sign options with local values.
         if ($key eq "encrypt"
             or $key eq "sign"
-            or $key eq "signify") {
+            or $key eq "signify"
+            or $key eq "gzip") {
             $profile{$section}{$key} = $config->{$section}->{$key};
             next;
         }
@@ -80,8 +82,11 @@ foreach my $prof ( @ARGV ) {
     if ( $profile{ $prof } ) {
         say "++++++++********++++++++";
 
+        my $file = "$backup_dir/${prof}/${date}.tar";
+        $file .= ".gz" if $profile{$prof}{gzip};
+
         path("$backup_dir/${prof}")->mkpath; # Create backup directory.
-        backup($prof);
+        backup($prof, $file);
 
         unless ($options{signify_and_gnupg_warning_disable}) {
             warn "
@@ -94,8 +99,8 @@ warning.
                     and ($profile{$prof}{encrypt} or $profile{$prof}{sign}));
     }
 
-        signify($prof) if $profile{$prof}{signify};
-        encrypt_sign($prof) if $profile{$prof}{sign} or $profile{$prof}{encrypt};
+        signify($prof, $file) if $profile{$prof}{signify};
+        encrypt_sign($prof, $file) if $profile{$prof}{sign} or $profile{$prof}{encrypt};
     } else {
         warn "[WARN] leo: no such profile :: `$prof' \n";
     }
@@ -103,7 +108,10 @@ warning.
 
 sub backup {
     my $prof = shift @_;
-    my $tar_file = "$backup_dir/${prof}/${date}.tar";
+    my $tar_file = shift @_;
+
+    my @options;
+    push @options, "-z" if $profile{$prof}{gzip};
 
     # Make @backup_paths relative to '/'.
     my @backup_paths;
@@ -133,20 +141,22 @@ sub backup {
     print "\n";
 
     # All paths should be relative to '/'.
-    tar_create($tar_file, "-C", '/', @backup_paths);
+    tar_create($tar_file, @options, "-C", '/', @backup_paths);
 
     $? # tar returns 1 on errors.
         ? die "Backup creation failed :: $?\n"
         # Print absolute paths for all backup files/directories.
         : say path($_)->absolute('/'), " backed up." foreach @backup_paths;
 
+    print "File was compress with gzip(1)\n" if $profile{$prof}{gzip};
+
     print "\n" and tar_list($tar_file) if $options{verbose};
 }
 
 # Encrypt, Sign backups.
 sub encrypt_sign {
     my $prof = shift @_;
-    my $file = "$backup_dir/${prof}/${date}.tar";
+    my $file = shift @_;
 
     my @options = ();
     push @options, "--default-key", $gpg_fingerprint;
@@ -179,7 +189,7 @@ sub encrypt_sign {
 
 sub signify {
     my $prof = shift @_;
-    my $file = "$backup_dir/${prof}/${date}.tar";
+    my $file = shift @_;
 
     die "\nSignify: seckey doesn't exist\n"
         unless $options{signify_seckey} and -e $options{signify_seckey};
@@ -210,6 +220,7 @@ Profile:};
         print " [Encrypt]" if $profile{$prof}{encrypt};
         print " [Sign]" if $profile{$prof}{sign};
         print " [Signify]" if $profile{$prof}{signify};
+        print " [gzip]" if $profile{$prof}{gzip};
         print "\n";
         print "        $_\n" foreach $profile{$prof}{backup}->@*;
         print "\n";
@@ -227,6 +238,11 @@ Profile:};
     print "[Enabled]" if $options{signify};
     print qq{
         Sign with signify(1)\n
+    --gzip };
+        print "[Enabled]" if $options{gzip};
+    print qq{
+        Compress with gzip(1)
+
     --verbose
     --help
 };
diff --git a/share/leo.conf b/share/leo.conf
index 8ccfb02..75e9d0a 100644
--- a/share/leo.conf
+++ b/share/leo.conf
@@ -24,6 +24,9 @@ signify = 1
 /home/andinus/documents/archive.org =
 
 [emacs]
+# compress this archive
+gzip = 1
+
 /home/andinus/.emacs.d =
 /home/andinus/.elfeed =
 /home/andinus/.org-timestamps =