#!/usr/bin/perl

$device = shift || die "Please specify full tapedevice\n";
$dd = "/bin/dd";
$mt = "/bin/mt";

print "Rewinding\n";
system("$mt -f $device rewind");

$tapeheader = `$dd if=$device bs=32k count=1`;
die "Amanda Label not found!\n$tapeheader\n" unless $tapeheader =~ /TAPESTART/;
print $tapeheader;
push(@stuff,$tapeheader);

while ( ! $ierr ){
    $foo = `$dd if=$device bs=32k count=1 | head -3`;
    if ($foo =~ /TAPEEND/) {
	print $foo;
	last;
    } elsif ($foo =~ /FILE/) {
	print $foo;
    } else {
	$foo =~ tr/A-Za-z0-9 \t\r\n/ /cs;
	print "Unexpected thing: $foo\n";
    }
    $ierr = $?;
}
print "Rewinding\n";
system("$mt -f $device rewind");
