bin/imager.restore
changeset 40 b8f8ec90c296
parent 38 fac6d76d06e8
child 42 b5db10953648
equal deleted inserted replaced
36:f361d688365c 40:b8f8ec90c296
     1 #! /usr/bin/perl
     1 #! /usr/bin/perl
     2 # Eigentlich geht das selbe mit:
     2 # Eigentlich geht das selbe mit:
     3 # grep '^[[:space:]]*[[:digit:]]' IDX-file | tr -d | cut -f4 -d' ' | while read f; do
     3 # grep '^[[:space:]]*[[:digit:]]' IDX-file | tr -d | cut -f4 -d' ' | while read f; do
     4 #	cat DATA/$f || zcat DATA/$f.gz
     4 #       if   test -f DATA/$f      then cat $f
     5 # done
     5 #	elif test -f DATA/$f.gz   then zcat DATA/$f.gz
     6 # ODER
     6 #       elif test -f DATA/$f.x    then openssl aes-128-cbc -d -in DATA/$f.x
     7 # perl -ne '/^\s*\d/ and print "DATA/" . (split)[2] . "\n"' IDX-File | while read f; do
     7 #	elif test -f DATA/$f.gz.x then openssl aes-128-cbc -d -in DATA/$f.gz.x | zcat
     8 #	cat DATA/$f || zcat DATA/$f.gz
     8 #	elif test -f DATA/$f.x.gz then zcat DATA/$f.x.gz | openssl aes-128-cbs -d 
       
     9 #	fi
     9 # done
    10 # done
    10 
    11 
    11 use 5.010;
    12 use 5.010;
    12 use strict;
    13 use strict;
    13 use warnings;
    14 use warnings;
    14 use File::Basename;
    15 use File::Basename;
    15 use Cwd qw(abs_path);
    16 use Cwd qw(abs_path);
    16 use autodie qw(:all);
    17 use autodie qw(:all);
    17 use Pod::Usage;
    18 use Pod::Usage;
    18 use Getopt::Long;
    19 use Getopt::Long;
       
    20 use Hash::Util qw(lock_keys);
    19 use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
    21 use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
    20 
    22 
    21 use constant KiB => 1024;
    23 use constant KiB => 1024;
    22 use constant MiB => 1024 * KiB;
    24 use constant MiB => 1024 * KiB;
    23 use constant GiB => 1024 * MiB;
    25 use constant GiB => 1024 * MiB;
    24 use constant ME  => basename $0;
    26 use constant ME  => basename $0;
       
    27 use constant CIPHER => "aes-128-cbc";
       
    28 
       
    29 my %o = (pass => "stdin");
       
    30 lock_keys(%o);
    25 
    31 
    26 sub find_data_dir;
    32 sub find_data_dir;
    27 
    33 
    28 MAIN: {
    34 MAIN: {
    29 
    35 
    30     Getopt::Long::Configure(qw(Bundling));
    36     Getopt::Long::Configure(qw(Bundling));
    31     GetOptions(
    37     GetOptions(
    32         "h|help" => sub { pod2usage(-verbose => 1, -exit => 0) },
    38         "p|pass=s" => \$o{pass},
    33         "m|man"  => sub {
    39         "h|help"   => sub { pod2usage(-verbose => 1, -exit => 0) },
       
    40         "m|man"    => sub {
    34             pod2usage(
    41             pod2usage(
    35                 -verbose   => 2,
    42                 -verbose   => 2,
    36                 -exit      => 0,
    43                 -exit      => 0,
    37                 -noperldoc => system(
    44                 -noperldoc => system(
    38                     "perldoc -V 1>/dev/null
    45                     "perldoc -V 1>/dev/null
    64         my ($in, $buffer);
    71         my ($in, $buffer);
    65 
    72 
    66         if (-f "$data/$path") {
    73         if (-f "$data/$path") {
    67             open($in => "$data/$path");
    74             open($in => "$data/$path");
    68             binmode($in);
    75             binmode($in);
    69             local $/ = \$blocksize;
    76             local $/ = undef;
    70             $buffer = <$in>;
    77             $buffer = <$in>;
    71         }
    78         }
    72         elsif (-f "$data/$path.gz") {
    79         elsif (-f "$data/$path.gz") {
    73             open($in => "$data/$path.gz");
    80             open($in => "$data/$path.gz");
    74             binmode($in);
    81             binmode($in);
    75             gunzip($in => \$buffer)
    82             gunzip($in => \$buffer)
    76               or die $GunzipError;
    83               or die $GunzipError;
       
    84         }
       
    85         elsif (-f "$data/$path.x") {
       
    86             open($in, "openssl @{[CIPHER]} -d -pass $o{pass} -in '$data/$path.x'|");
       
    87             binmode($in);
       
    88             local $/ = undef;
       
    89             $buffer = <$in>;
       
    90         }
       
    91         elsif (-f "$data/$path.gz.x") {
       
    92             open($in, "openssl @{[CIPHER]} -d -pass $o{pass} -in $data/$path.gz.x|");
       
    93             binmode($in);
       
    94             gunzip($in => \$buffer)
       
    95               or die $GunzipError;
       
    96         }
       
    97         elsif (-f "$data/$path.x.gz") {
       
    98             warn "$data/$path.x.gz: depreciated!\n";
       
    99             open($in,
       
   100                 "gzip -d -c $data/$path.x.gz | openssl @{[CIPHER]} -d -pass $o{pass}|");
       
   101             binmode($in);
       
   102             local $/ = undef;
       
   103             $buffer = <$in>;
    77         }
   104         }
    78         else {
   105         else {
    79             die ME . ": Can't open $data/$path: $!\n";
   106             die ME . ": Can't open $data/$path: $!\n";
    80         }
   107         }
    81         print {$out} $buffer;
   108         print {$out} $buffer;
    98 
   125 
    99     imager.restore - cats the blocks of the imager
   126     imager.restore - cats the blocks of the imager
   100 
   127 
   101 =head1 SYNOPSIS
   128 =head1 SYNOPSIS
   102 
   129 
   103     imager.restore {idx} {destination}
   130     imager.restore [options] {idx} {destination}
   104 
   131 
   105 =head1 DESCRIPTION
   132 =head1 DESCRIPTION
   106 
   133 
   107 The B<imager.restore> takes all the blocks from the IDX file and
   134 The B<imager.restore> takes all the blocks from the IDX file and
   108 cats them as one data stream. The destination can be any block device,
   135 cats them as one data stream. The destination can be any block device,
   109 a file name or even B<-> (STDOUT).
   136 a file name or even B<-> (STDOUT).
   110 
   137 
       
   138 =head1 OPTIONS
       
   139 
       
   140 =over
       
   141 
       
   142 =item B<-p> I<pass> | B<--pass=>I<pass>
       
   143 
       
   144 In case you expect encrypted data, this option takes the argument for
       
   145 B<openssl>'s C<-pass> option. See L<openssl(3)> for mor information.
       
   146 (default: stdin)
       
   147 
       
   148 =item B<-h>|B<--help>
       
   149 
       
   150 =item B<-m>|B<--man>
       
   151 
       
   152 The standard help options.
       
   153 
       
   154 =back
   111 
   155 
   112 =cut
   156 =cut