#! /usr/bin/perl # # $Id$ use strict; use warnings; use IO::Handle; use Cwd qw(chdir fastgetcwd); use constant FORMATS=>{ "rpm"=>'rpm2cpio !|cpio -id --quiet', #-v #FIXME: --sparse doesn't work, why? "zip"=>'unzip -Lq !', "a" =>'ar x !', "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', }; die "Syntax: $0 )>..." if !@ARGV; my $origdir=fastgetcwd; for my $fname (@ARGV) { $fname=~m#([^/]+)([.=])(\L[^./]+\E)$# or die "Extension not found for archive: $fname"; my($path,$base,$ext)=($`,$1,$3); my($pathname)=($2 eq "=" ? "$path$base" : $fname); my $cmd=FORMATS->{$ext} or die "Extension \"$ext\" not known for archive: $fname"; -r $pathname && !-d $pathname or die "Archive not readable: $pathname"; my($extdir)=(-e $base && !-d $base ? "$base.dir" : $base); -d $extdir or mkdir $extdir or die "Unable to create directory \"$extdir\": $!"; chdir $extdir or die "Unable to chdir to \"$extdir\": $!"; $pathname="../$pathname" if $pathname!~m#^/#; $pathname=~s/'/'\\''/g; $pathname="'$pathname'"; $cmd=~s/!/$pathname/g; $cmd="set -ex;$cmd"; print "\t$extdir/:\n"; STDOUT->flush(); my $rc; $rc=system $cmd and die "$cmd (rc=".($rc>>8)."): $!"; } continue { chdir $origdir; } exit 0;