X-Git-Url: https://git.jankratochvil.net/?p=nethome.git;a=blobdiff_plain;f=bin%2Fexx;h=97f021b2200a28213c514f973d1866b64d0ec9a5;hp=12de60d3b538387afdbe0277519d1bf524b1eafb;hb=c36d3924d6aa4ea711f344e215e2f5b8525fd0a0;hpb=2a0c64fca6c94cad5b5978328763688d77ced891 diff --git a/bin/exx b/bin/exx index 12de60d..97f021b 100755 --- a/bin/exx +++ b/bin/exx @@ -8,36 +8,41 @@ use warnings; use IO::Handle; use Cwd qw(chdir cwd); -use constant FORMAT_TAR_GZ=>'tar xzf $pathname;i=`echo *`;echo "$i"|grep -q " " || test * != $base ||' - .'(mv "$i" "$i".$$;(set +x;mv "$i".$$/* .);rmdir "$i".$$)'; +use constant FORMAT_TAR=>'tar xf $pathname;i=`echo *`;echo "$i"|grep -q " " || test * != $base ||' + .'(mv "$i" "$i".$$;(set +x;mv "$i".$$/* .);rmdir "$i".$$)'; use constant FORMATS=>{ "rpm" =>'rpm2cpio $pathname|cpio -id --quiet', #-v #FIXME: --sparse doesn't work, why? "zip" =>'unzip -Lq $pathname', + "jar" =>'unzip -Lq $pathname', "a" =>'ar x $pathname', "deb" =>'ar x $pathname;' .'for i in *.tar.gz;do j=`basename $i .tar.gz`;mkdir -p $j;cd $j;tar xzf ../$i;cd ..;rm -f $i;done', "arj" =>'unarj x $pathname', - "tar.gz" =>FORMAT_TAR_GZ, + "tar" =>FORMAT_TAR, + "tar.gz" =>do { $_=FORMAT_TAR; s/xf/xzf/; $_; }, "tgz" =>"tar.gz", - "tar.bz2"=>do { $_=FORMAT_TAR_GZ; s/xzf/xjf/; $_; }, + "tar.bz2"=>do { $_=FORMAT_TAR; s/xf/xjf/; $_; }, "tar.bz" =>"tar.bz2", "tbz" =>"tar.bz", + "tar.xz" =>do { $_=FORMAT_TAR; s/xf/xJf/; $_; }, + "txz" =>do { $_=FORMAT_TAR; s/xf/xJf/; $_; }, + "msi" =>'cabextract -q $pathname', }; die "Syntax: $0 )>..." if !@ARGV; +my @extdirs; my $origdir=cwd; for my $fname (@ARGV) { my @parsed; for my $fmt (sort { length $b<=>length $a; } keys %{+FORMATS}) { - (my $fmtt=$fmt)=~s/(\W)/\\$1/g; - last if @parsed=$fname=~m#^(.*?)([^/]+)([.=])($fmtt)$#i; + last if @parsed=$fname=~m#^(.*?)([^/]+)([.=])(\Q$fmt\E)$#i; } $parsed[3] or die "Extension not found for archive: $fname"; my($path,$base,$ext)=@parsed[0,1,3]; my($pathname)=($parsed[2] eq "=" ? "$path$base" : $fname); - my($cmdtry,$cmd)=($ext); + my($cmdtry,$cmd)=(lc $ext); do { $cmd=$cmdtry; $cmdtry=FORMATS->{$cmdtry}; @@ -65,8 +70,10 @@ for my $fname (@ARGV) { print "\t$extdir/:\n"; STDOUT->flush(); my $rc; $rc=system $cmd and die "$cmd (rc=".($rc>>8)."): $!"; + push @extdirs,$extdir; } continue { chdir $origdir; } +print "extdir=".$extdirs[0]."\n" if 1==@extdirs; exit 0;