Debian Codegraph @

eg/tarflat

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