about summary refs log tree commit diff stats
path: root/082persist.cc
Commit message (Expand)AuthorAgeFilesLines
* 2258 - separate warnings from errorsKartik K. Agaram2015-10-061-7/+7
* 2232Kartik K. Agaram2015-10-011-18/+39
* 2226 - standardize warning formatKartik K. Agaram2015-10-011-5/+5
* 2196Kartik K. Agaram2015-09-141-3/+0
* 2183 - environment + external editor using tmuxKartik K. Agaram2015-09-121-1/+6
* 2095Kartik K. Agaram2015-08-281-2/+0
* 1987Kartik K. Agaram2015-08-131-6/+0
* 1923Kartik K. Agaram2015-08-021-1/+1
* 1915 - restore expected response from diskKartik K. Agaram2015-08-011-5/+9
* 1913 - save expected response for each sandboxKartik K. Agaram2015-08-011-7/+15
* 1900Kartik K. Agaram2015-07-301-1/+2
* 1886 - gracefully handle malformed ingredientsKartik K. Agaram2015-07-291-2/+4
* 1867 - keep tests from corrupting lesson/ directoryKartik K. Agaram2015-07-281-2/+4
* 1851Kartik K. Agaram2015-07-251-2/+2
* 1848 - core instructions now check for ingredientsKartik K. Agaram2015-07-251-3/+11
* 1844 - explicitly end each trace lineKartik K. Agaram2015-07-251-4/+4
* 1823 - restore sandboxes from previous sessionKartik K. Agaram2015-07-191-6/+16
* 1822Kartik K. Agaram2015-07-191-2/+2
* 1817 - save for sandboxesKartik K. Agaram2015-07-181-7/+19
* 1816 - ack, accidental namespace collisionKartik K. Agaram2015-07-181-4/+4
* 1815 - git commit only if lesson/.git existsKartik K. Agaram2015-07-181-0/+10
* 1814 - save code in editorKartik K. Agaram2015-07-181-0/+50
8 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
93





                  
              







                                             
 



                                                                      
                
                           

  




                                      
        





                              























































                                                                        
 
#!/usr/bin/perl

use strict;
use warnings;
use feature 'say';

use IPC::Run3;
use Path::Tiny;
use Getopt::Long qw/ GetOptions /;

my %options = ();
GetOptions(
    \%options,
    qw{ verbose }
) or die "Error in command line arguments\n";


# There will be multiple dispatch tables, to avoid confusion the main
# one is named %dispatch & others will be named like %archive_dispatch
# & so on.
my %dispatch = (
    "archive" => \&archive,
);

if ( $ARGV[0]
         and $dispatch{ $ARGV[0] } ) {
    $dispatch{ $ARGV[0] }->();
} elsif ( scalar @ARGV == 0 ) {
    HelpMessage();
} else {
    say "leo: no such option";
}

sub HelpMessage {
    say qq{Usage:
    archive
        Create an archive.};
}

sub rsync { run3 ["openrsync", @_]; }
sub tar_create { run3 ["/bin/tar", "cf", @_]; }
sub tar_list { run3 ["/bin/tar", "tvf", @_]; }

# Creating tars of files.
sub archive {
    my %archive_dispatch = (
        "documents" => sub {
            tar_create("/tmp/archive/documents.tar",
                       # Won't print "tar: Removing leading / from
                       # absolute path names in the archive" to
                       # STDERR.
                       "-C", "$ENV{HOME}/documents", ".");

            $? # tar returns 1 on errors.
                ? die "Archive creation failed :: $?\n"
                : say "$ENV{HOME}/documents archived.";
            tar_list("/tmp/archive/documents.tar") if $options{verbose};
        },
        "journal" => sub {
            tar_create("/tmp/archive/journal.tar",
                       "-C", "$ENV{HOME}/documents",
                       "andinus.org.gpg", "archive.org.gpg");

            $?
                ? die "Archive creation failed :: $?\n"
                : say "$ENV{HOME}/documents/andinus.org.gpg,
$ENV{HOME}/documents/archive.org.gpg archived.";
            tar_list("/tmp/archive/journal.tar") if $options{verbose};
        },
    );

    shift @ARGV;
    if ( $ARGV[0]
             and $archive_dispatch{ $ARGV[0] } ) {
        path("/tmp/archive")->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.

Usage:
    documents
        Archive $ENV{HOME}/documents
    journal
        Archive $ENV{HOME}/documents/andinus.org.gpg,
                $ENV{HOME}/documents/archive.org.gpg};
    }
}