#!/usr/bin/perl

$file=$ARGV[0];

exit 0 if -s $file < 1000000;

mkdir("$file-split", 0777) || die "$0: mkdir $file-split: $!\n";
!system("bsplit $file 256000") || die "$0: couldn't bsplit $file: $!\n";

$fromend='aa';
$toend='part01';

while (-f "$file.$fromend") {
  $from="$file.$fromend";
  $to="$file-split/$toend";
  rename($from, $to) || die "$0: rename $from $to: $!\n";
  $fromend++, $toend++;
}

unlink($file);
chdir "$file-split";
open(STDOUT, "> README");
$sum=`sum part*`;

print <<EOF;
This directory contains a splitup version of $file.
To recreate the original simply concatenate all the
parts back together.

Checksums are:

$sum
EOF

exit(0);
