X-Git-Url: https://git.jankratochvil.net/?p=nethome.git;a=blobdiff_plain;f=bin%2Fexx;fp=bin%2Fexx;h=df78524508419e6376969cc60433164f3a1c9501;hp=0000000000000000000000000000000000000000;hb=43d855aea466f7f8e1e7a3e31440abf8b3bd6404;hpb=6265f1662c8c2818a22c591ae63a6cdfa69bd5f2 diff --git a/bin/exx b/bin/exx new file mode 100755 index 0000000..df78524 --- /dev/null +++ b/bin/exx @@ -0,0 +1,43 @@ +#! /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;