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 "msi" =>'cabextract -q $pathname',
30 die "Syntax: $0 <pathname((".join("|",map(".$_",sort keys %{+FORMATS})).")|=<ext>)>..."
35 for my $fname (@ARGV) {
37 for my $fmt (sort { length $b<=>length $a; } keys %{+FORMATS}) {
38 last if @parsed=$fname=~m#^(.*?)([^/]+)([.=])(\Q$fmt\E)$#i;
40 $parsed[3] or die "Extension not found for archive: $fname";
41 my($path,$base,$ext)=@parsed[0,1,3];
42 my($pathname)=($parsed[2] eq "=" ? "$path$base" : $fname);
43 my($cmdtry,$cmd)=(lc $ext);
46 $cmdtry=FORMATS->{$cmdtry};
48 -r $pathname && !-d $pathname or die "Archive not readable: $pathname";
49 my($extdir)=(-e $base && !-d $base ? "$base.dir" : $base);
50 # Extraction-overwriting cowardly not supported:
52 mkdir $extdir or die "Unable to create directory \"$extdir\": $!";
53 chdir $extdir or die "Unable to chdir to \"$extdir\": $!";
54 $pathname="../$pathname" if $pathname!~m#^/#;
55 $path ="../$path" if $path !~m#^/#;
58 "pathname"=>\$pathname,
64 while (my($name,$var)=each %substvars) {
65 ($_=$$var)=~s/'/'\\''/g;
66 $cmd="$name='$_';$cmd";
68 print "\t$extdir/:\n"; STDOUT->flush();
70 $rc=system $cmd and die "$cmd (rc=".($rc>>8)."): $!";
71 push @extdirs,$extdir;
76 print "extdir=".$extdirs[0]."\n" if 1==@extdirs;