1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
use Pod::Usage;
use Archive::Tar::Wrapper;
use Sysadm::Install qw(:all);
use vars qw($CVSVERSION);
$CVSVERSION = '$Revision: 1.1 $';
getopts( "hv", \my %opts );
pod2usage() if $opts{h};
if ( $opts{v} ) {
my ($version) = $CVSVERSION =~ /(\d\S+)/;
die "$0 $version\n";
}
my ( $target_dir, @tarfiles ) = @ARGV;
unless ( defined($target_dir) or @tarfiles ) {
pod2usage("Wrong number of arguments");
}
unless ( -d $target_dir ) {
my $create = ask "$target_dir doesn't exist. Create it [y]", "y";
mkd $target_dir if $create =~ /[yY]/;
}
my $arch = Archive::Tar::Wrapper->new();
for my $tarfile (@tarfiles) {
$arch->read($tarfile);
}
$arch->list_reset();
while ( my $entry = $arch->list_next() ) {
my ( $tar_path, $phys_path ) = @$entry;
if ( -f $phys_path ) {
cp $phys_path, $target_dir;
}
}
__END__
=head1 NAME
tarflat - Unpack tarfiles and put their content flat in a single directory
=head1 SYNOPSIS
tarflat target_dir tarfile ...
=head1 OPTIONS
=over 8
=item B<-h>
Prints this manual page in text format.
=item B<-v>
Prints the script version.
=back
=head1 DESCRIPTION
C<tarflat>
=head1 EXAMPLES
# Unpack foo.tgz and bar.tgz and store all of their files
# (anywhere in the directory hierarchy) in the directory
# /tmp/junk.
$ mkdir /tmp/junk
$ tarflat /tmp/junk foo.tgz bar.tgz
=head1 LEGALESE
This software is copyright (c) 2005 of Mike Schilli.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
Archive-Tar-Wrapper. If not, see L<http://www.gnu.org/licenses/>.
=head1 AUTHOR
2005, Mike Schilli <cpan@perlmeister.com>
=head1 MAINTAINER
2018, Alceu Rodrigues de Freitas Junior <glasswalk3r@yahoo.com.br>
=cut
|