#! /usr/bin/perl -w
#
# test script to run the iso unpacker.
# 2008-09-17, jw
my $isoinfo = 'isoinfo'; # Requires: genisoimage
my $verbose = 0;
my $from = shift;
my $outdir = shift || 'out';
mkdir $outdir;
my $cmd = "$isoinfo -d -i '$from'";
open my $fd, "-|", $cmd;
my $text = join '', <$fd>;
close $fd;
open O, '>', "$outdir/.isoinfo";
print O $text;
close O;
my $opt = '';
$opt = '-J' if $text =~ m{^Joliet\b}m;
$opt = '-R' if $text =~ m{^Rock Ridge\b}m;
$cmd = "$isoinfo $opt -f -i '$from'";
print "running: $cmd\n" if $verbose;
open $fd, "-|", $cmd;
my @files = <$fd>;
close $fd;
chomp @files;
for my $f (@files)
{
my $of = "$outdir/$f";
mkdir_pf($of);
$cmd = "$isoinfo $opt -x '$f' -i '$from' > '$of'";
print "extracting '$of' ...\n" if $verbose;
system $cmd and die "command failed: $cmd: $!\n";
}
exit 0;
#################################
##
## this version of mkdir_pf handles relative and absolute paths.
##
sub mkdir_pf
{
my ($path) = @_;
my @dirs = split "/", $path;
pop @dirs; # nuke trailing filename
$path = ($dirs[0] eq '') ? '/' : '';
for my $d (@dirs)
{
$path .= "$d/";
mkdir $path, 0777 or die "mkdir $path failed: $!" unless -d $path;
}
return 1; # success, be mkdir compatible
}