9 use Cwd qw(chdir fastgetcwd);
11 use constant FORMATS=>{
12 "rpm"=>'rpm2cpio !|cpio -id --quiet', #-v #FIXME: --sparse doesn't work, why?
15 "deb"=>'ar x !;for i in *.tar.gz;do j=`basename $i .tar.gz`;mkdir -p $j;cd $j;tar xzf ../$i;cd ..;rm -f $i;done',
18 die "Syntax: $0 <pathname((".join("|",map(".$_",sort keys %{+FORMATS})).")|=<ext>)>..."
21 my $origdir=fastgetcwd;
22 for my $fname (@ARGV) {
23 $fname=~m#([^/]+)([.=])(\L[^./]+\E)$# or die "Extension not found for archive: $fname";
24 my($path,$base,$ext)=($`,$1,$3);
25 my($pathname)=($2 eq "=" ? "$path$base" : $fname);
26 my $cmd=FORMATS->{$ext} or die "Extension \"$ext\" not known for archive: $fname";
27 -r $pathname && !-d $pathname or die "Archive not readable: $pathname";
28 my($extdir)=(-e $base && !-d $base ? "$base.dir" : $base);
29 -d $extdir or mkdir $extdir or die "Unable to create directory \"$extdir\": $!";
30 chdir $extdir or die "Unable to chdir to \"$extdir\": $!";
31 $pathname="../$pathname" if $pathname!~m#^/#;
32 $pathname=~s/'/'\\''/g;
33 $pathname="'$pathname'";
34 $cmd=~s/!/$pathname/g;
36 print "\t$extdir/:\n"; STDOUT->flush();
38 $rc=system $cmd and die "$cmd (rc=".($rc>>8)."): $!";