bin/imager.fuse
changeset 44 f1fea4381014
parent 42 b5db10953648
child 51 0b6b92d1eb65
equal deleted inserted replaced
43:27f0c30c5240 44:f1fea4381014
    20     tmp    => undef,
    20     tmp    => undef,
    21     pass   => undef,
    21     pass   => undef,
    22 );
    22 );
    23 lock_keys %o;
    23 lock_keys %o;
    24 
    24 
    25 use constant ME => basename $0;
    25 use constant ME     => basename $0;
    26 use constant BS => 4 * 1024;
    26 use constant BS     => 4 * 1024;
    27 use constant CIPHER => "aes-128-cbc";
    27 use constant CIPHER => "aes-128-cbc";
    28 
    28 
    29 my ($DATA, $IDX);
    29 my ($DATA, $IDX);
    30 
    30 
    31 sub tie_vars;
    31 sub tie_vars;
    46 
    46 
    47     GetOptions(
    47     GetOptions(
    48         "d|debug!" => \$o{debug},
    48         "d|debug!" => \$o{debug},
    49         "detach!"  => \$o{detach},
    49         "detach!"  => \$o{detach},
    50         "tmp:s" => sub { $o{tmp} = length $_[1] ? $_[1] : $ENV{TMP} // "/tmp" },
    50         "tmp:s" => sub { $o{tmp} = length $_[1] ? $_[1] : $ENV{TMP} // "/tmp" },
    51         "h|help" => sub { pod2usage(-verbose => 1, -exit => 0) },
    51         "h|help"   => sub { pod2usage(-verbose => 1, -exit => 0) },
    52 	"p|pass=s" => \$o{pass},
    52         "p|pass=s" => \$o{pass},
    53         "m|man"  => sub {
    53         "m|man"    => sub {
    54             pod2usage(
    54             pod2usage(
    55                 -verbose   => 2,
    55                 -verbose   => 2,
    56                 -exit      => 0,
    56                 -exit      => 0,
    57                 -noperlpod => system("perldoc -V 1>/dev/null 2>&1")
    57                 -noperlpod => system("perldoc -V 1>/dev/null 2>&1")
    58             );
    58             );
   228                 open(my $fh => "$fn.gz");
   228                 open(my $fh => "$fn.gz");
   229                 binmode($fh);
   229                 binmode($fh);
   230                 gunzip($fh => \$cache{data})
   230                 gunzip($fh => \$cache{data})
   231                   or die $GunzipError;
   231                   or die $GunzipError;
   232             }
   232             }
   233 	    elsif (-e "$fn.x") {
   233             elsif (-e "$fn.x") {
   234 		open(my $fh => "openssl @{[CIPHER]} -d -pass '$o{pass}' -in '$fn.x'|");
   234                 open(
   235 		binmode($fh);
   235                     my $fh =>
   236 		local $/ = undef;
   236                       "openssl @{[CIPHER]} -d -pass '$o{pass}' -in '$fn.x'|");
   237 		$cache{data} = <$fh>;
   237                 binmode($fh);
   238 		close($fh);
   238                 local $/ = undef;
   239 	    }
   239                 $cache{data} = <$fh>;
   240 	    elsif (-e "$fn.gz.x") {
   240                 close($fh);
   241 		open(my $fh => "openssl @{[CIPHER]} -d -pass '$o{pass}' -in '$fn.gz.x'|");
   241             }
   242 		binmode($fh);
   242             elsif (-e "$fn.gz.x") {
   243 		gunzip($fh => \$cache{data})
   243                 open(
   244 		    or die $GunzipError;
   244                     my $fh =>
   245 		close($fh);
   245                       "openssl @{[CIPHER]} -d -pass '$o{pass}' -in '$fn.gz.x'|"
   246 	    }
   246                 );
   247 	    elsif (-e "$fn.x.gz") {
   247                 binmode($fh);
   248 		warn "$fn.x.gz is depreciated!\n";
   248                 gunzip($fh => \$cache{data})
   249 		open(my $fh => "zcat $fn.x.gz | openssl @{[CIPHER]} -d -pass '$o{pass}'|");
   249                   or die $GunzipError;
   250 		binmode($fh);
   250                 close($fh);
   251 		local $/ = undef;
   251             }
   252 		$cache{data} = <$fh>;
   252             elsif (-e "$fn.x.gz") {
   253 		close($fh);
   253                 warn "$fn.x.gz is depreciated!\n";
   254 	    }
   254                 open(
       
   255                     my $fh =>
       
   256                       "zcat $fn.x.gz | openssl @{[CIPHER]} -d -pass '$o{pass}'|"
       
   257                 );
       
   258                 binmode($fh);
       
   259                 local $/ = undef;
       
   260                 $cache{data} = <$fh>;
       
   261                 close($fh);
       
   262             }
   255             $cache{fn} = $fn;
   263             $cache{fn} = $fn;
   256         }
   264         }
   257 
   265 
   258         return substr($cache{data}, $blockoffset, $length);
   266         return substr($cache{data}, $blockoffset, $length);
   259         die "$fn: $!\n";
   267         die "$fn: $!\n";