From 391977a559a3130885d5c512f25d76207ac67b16 Mon Sep 17 00:00:00 2001 From: Andinus Date: Thu, 27 Aug 2020 12:39:21 +0530 Subject: Add encrypt & sign option, remove archive_HelpMessage() `archive_HelpMessage' was removed because variables from `archive' sub are not shared with it. On #perl@freenode: i have a sub archive_Help inside of sub archive, when i try to use archive's var in archive_Help perl says "Variable "$archive_dir" will not stay shared at..." [02:55] [...] generally, you pass variables into subs that you call [02:57] defining a sub within another sub is evidence that you did it wrong [...] is defining a sub within a sub not a good idea? it does nothing useful [03:01] and causes issues like the one you are having [...] --- leo.pl | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/leo.pl b/leo.pl index 9f6482b..3c20e8e 100755 --- a/leo.pl +++ b/leo.pl @@ -11,7 +11,7 @@ use Getopt::Long qw/ GetOptions /; my %options = (); GetOptions( \%options, - qw{ verbose } + qw{ verbose encrypt sign } ) or die "Error in command line arguments\n"; @@ -75,6 +75,9 @@ sub tar_list { run3 ["/bin/tar", "tvf", @_]; } # Creating tars of files. sub archive { + my $gpg_fingerprint = "D9AE4AEEE1F1B3598E81D9DFB67D55D482A799FD"; + my $archive_dir = "/tmp/archive"; + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); @@ -89,37 +92,30 @@ sub archive { my %archive_dispatch = ( "documents" => sub { - tar_create("/tmp/archive/documents_$ymd.tar", + tar_create("$archive_dir/documents_$ymd.tar", "-C", "$ENV{HOME}/documents", "."); }, "journal" => sub { - tar_create("/tmp/archive/journal_$ymd.tar", + tar_create("$archive_dir/journal_$ymd.tar", "-C", "$ENV{HOME}/documents", "andinus.org.gpg", "archive.org.gpg"); }, "ssh" => sub { - tar_create("/tmp/archive/ssh_$ymd.tar", + tar_create("$archive_dir/ssh_$ymd.tar", "-C", "$ENV{HOME}/.ssh", "."); }, "pass" => sub { - tar_create("/tmp/archive/pass_$ymd.tar", + tar_create("$archive_dir/pass_$ymd.tar", "-C", "$ENV{HOME}/.password-store", "."); }, ); - shift @ARGV; - if ( $ARGV[0] - and $archive_dispatch{ $ARGV[0] } ) { - path("/tmp/archive")->mkpath; # Create archive directory. + shift @ARGV; # Drop `archive' from @ARGV. + if ( $ARGV[0] and $archive_dispatch{ $ARGV[0] } ) { + path($archive_dir)->mkpath; # Create archive directory. $archive_dispatch{ $ARGV[0] }->(); } elsif ( scalar @ARGV == 0 ) { - archive_HelpMessage(); - } else { - say "leo/archive: no such option"; - } - - sub archive_HelpMessage { - say qq{Archive files to /tmp/archive. + say qq{Archive files to $archive_dir. Usage: documents @@ -130,6 +126,14 @@ Usage: ssh Archive $ENV{HOME}/.ssh pass - Archive $ENV{HOME}/.password-store}; + Archive $ENV{HOME}/.password-store + +Options: + --encrypt + Encrypt files with $gpg_fingerprint + --sign + Sign files with $gpg_fingerprint}; + } else { + say "leo/archive: no such option"; } } -- cgit 1.4.1-2-gfad0