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 "xpi" =>'unzip -Lq $pathname',
18 "crx" =>'unzip -Lq $pathname',
19 "a" =>'ar x $pathname',
20 "deb" =>'ar x $pathname;'
21 .'for i in *.tar.gz;do j=`basename $i .tar.gz`;mkdir -p $j;cd $j;tar xzf ../$i;cd ..;rm -f $i;done',
22 "arj" =>'unarj x $pathname',
24 "tar.gz" =>do { $_=FORMAT_TAR; s/xf/xzf/; $_; },
26 "tar.bz2"=>do { $_=FORMAT_TAR; s/xf/xjf/; $_; },
29 "tar.xz" =>do { $_=FORMAT_TAR; s/xf/xJf/; $_; },
30 "txz" =>do { $_=FORMAT_TAR; s/xf/xJf/; $_; },
31 "msi" =>'cabextract -q $pathname',
34 die "Syntax: $0 <pathname((".join("|",map(".$_",sort keys %{+FORMATS})).")|=<ext>)>..."
39 for my $fname (@ARGV) {
41 for my $fmt (sort { length $b<=>length $a; } keys %{+FORMATS}) {
42 last if @parsed=$fname=~m#^(.*?)([^/]+)([.=])(\Q$fmt\E)$#i;
44 $parsed[3] or die "Extension not found for archive: $fname";
45 my($path,$base,$ext)=@parsed[0,1,3];
46 my($pathname)=($parsed[2] eq "=" ? "$path$base" : $fname);
47 my($cmdtry,$cmd)=(lc $ext);
50 $cmdtry=FORMATS->{$cmdtry};
52 -r $pathname && !-d $pathname or die "Archive not readable: $pathname";
53 my($extdir)=(-e $base && !-d $base ? "$base.dir" : $base);
54 # Extraction-overwriting cowardly not supported:
56 mkdir $extdir or die "Unable to create directory \"$extdir\": $!";
57 chdir $extdir or die "Unable to chdir to \"$extdir\": $!";
58 $pathname="../$pathname" if $pathname!~m#^/#;
59 $path ="../$path" if $path !~m#^/#;
62 "pathname"=>\$pathname,
68 while (my($name,$var)=each %substvars) {
69 ($_=$$var)=~s/'/'\\''/g;
70 $cmd="$name='$_';$cmd";
72 print "\t$extdir/:\n"; STDOUT->flush();
74 $rc=system $cmd and die "$cmd (rc=".($rc>>8)."): $!";
75 push @extdirs,$extdir;
80 print "extdir=".$extdirs[0]."\n" if 1==@extdirs;