11 use constant FORMAT_TAR=>'tar xf $pathname;i=`echo *`;echo "$i"|grep -q " " || test * != $base ||'
12 .'(mv "$i" "$i".$$;(set +x;mv "$i".$$/* .);rmdir "$i".$$)';
13 use constant FORMATS=>{
14 "rpm" =>'rpm2cpio $pathname|cpio -id --quiet', #-v #FIXME: --sparse doesn't work, why?
15 "zip" =>'unzip -Lq $pathname',
16 "jar" =>'unzip -Lq $pathname',
17 "a" =>'ar x $pathname',
18 "deb" =>'ar x $pathname;'
19 .'for i in *.tar.gz;do j=`basename $i .tar.gz`;mkdir -p $j;cd $j;tar xzf ../$i;cd ..;rm -f $i;done',
20 "arj" =>'unarj x $pathname',
22 "tar.gz" =>do { $_=FORMAT_TAR; s/xf/xzf/; $_; },
24 "tar.bz2"=>do { $_=FORMAT_TAR; s/xf/xjf/; $_; },
27 "tar.xz" =>do { $_=FORMAT_TAR; s/xf/xJf/; $_; },
28 "txz" =>do { $_=FORMAT_TAR; s/xf/xJf/; $_; },
29 "msi" =>'cabextract -q $pathname',
32 die "Syntax: $0 <pathname((".join("|",map(".$_",sort keys %{+FORMATS})).")|=<ext>)>..."
37 for my $fname (@ARGV) {
39 for my $fmt (sort { length $b<=>length $a; } keys %{+FORMATS}) {
40 last if @parsed=$fname=~m#^(.*?)([^/]+)([.=])(\Q$fmt\E)$#i;
42 $parsed[3] or die "Extension not found for archive: $fname";
43 my($path,$base,$ext)=@parsed[0,1,3];
44 my($pathname)=($parsed[2] eq "=" ? "$path$base" : $fname);
45 my($cmdtry,$cmd)=(lc $ext);
48 $cmdtry=FORMATS->{$cmdtry};
50 -r $pathname && !-d $pathname or die "Archive not readable: $pathname";
51 my($extdir)=(-e $base && !-d $base ? "$base.dir" : $base);
52 # Extraction-overwriting cowardly not supported:
54 mkdir $extdir or die "Unable to create directory \"$extdir\": $!";
55 chdir $extdir or die "Unable to chdir to \"$extdir\": $!";
56 $pathname="../$pathname" if $pathname!~m#^/#;
57 $path ="../$path" if $path !~m#^/#;
60 "pathname"=>\$pathname,
66 while (my($name,$var)=each %substvars) {
67 ($_=$$var)=~s/'/'\\''/g;
68 $cmd="$name='$_';$cmd";
70 print "\t$extdir/:\n"; STDOUT->flush();
72 $rc=system $cmd and die "$cmd (rc=".($rc>>8)."): $!";
73 push @extdirs,$extdir;
78 print "extdir=".$extdirs[0]."\n" if 1==@extdirs;