version 1.23, 2010/02/25 17:54:13 |
version 1.25, 2010/03/22 21:15:06 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# -T |
# -T |
#$RedRiver: MakeTorrents.pl,v 1.22 2007/11/02 02:36:01 andrew Exp $ |
#$RedRiver: MakeTorrents.pl,v 1.24 2010/03/08 20:19:37 andrew Exp $ |
use strict; |
use strict; |
use warnings; |
use warnings; |
use diagnostics; |
use diagnostics; |
|
|
|
|
my ($dirs, $files) = Get_Files_and_Dirs($basedir); |
my ($dirs, $files) = Get_Files_and_Dirs($basedir); |
if (@$files) { |
if (@$files) { |
my $torrent = Make_Torrent($basedir, $files); |
Make_Torrent($basedir, $files); |
} |
} |
|
|
# don't recurse if we were started with a specific directory |
# don't recurse if we were started with a specific directory |
|
|
{ |
{ |
my $basedir = shift; |
my $basedir = shift; |
my $files = shift; |
my $files = shift; |
my $ignore_too_few = shift || 0; |
|
|
|
my $torrent_base = $basedir; |
|
my $comment = "Files from $torrent_base\n"; |
|
if ($ignore_too_few && $files->[0] =~ /$INSTALL_ISO_REGEX/) { |
|
$torrent_base = "$basedir/$files->[0]"; |
|
$comment = "$torrent_base\n"; |
|
} |
|
elsif ($#{ $files } < $OBT->{MIN_FILES}) { |
|
print "Too few files in $basedir, skipping . . .\n"; |
|
return undef; |
|
} |
|
|
|
if ($basedir !~ /\.\./ && $basedir =~ /^([\w\/\.-]+)$/) { |
if ($basedir !~ /\.\./ && $basedir =~ /^([\w\/\.-]+)$/) { |
$basedir = $1; |
$basedir = $1; |
} else { |
} else { |
die "Invalid characters in dir '$basedir'"; |
die "Invalid characters in dir '$basedir'"; |
} |
} |
|
|
my @good_files; |
if ($#{ $files } < $OBT->{MIN_FILES}) { |
|
print "Too few files in $basedir, skipping . . .\n"; |
|
return undef; |
|
} |
|
|
|
my $torrent = Name_Torrent($basedir); |
|
my $comment = "Files from $basedir"; |
|
|
|
my %torrents; |
foreach my $file (@$files) { |
foreach my $file (@$files) { |
if ((!$ignore_too_few) && $file =~ /$INSTALL_ISO_REGEX/) { |
if ($file =~ /^([^\/]+)$/) { |
my @f = ($file); |
$file = $1; |
#foreach my $f (@$files) { |
|
# if ($f =~ /INSTALL|MD5/) { |
my $t = $torrent; |
# push @f, $f; |
my $c = $comment; |
# } |
|
#} |
if ($file =~ /$INSTALL_ISO_REGEX/xms) { |
Make_Torrent($basedir, \@f, 1) |
$t = Name_Torrent("$basedir/$file"); |
} |
$c = "$basedir/$file"; |
elsif ($file =~ /^([^\/]+)$/) { |
} |
push @good_files, "$basedir/$1"; |
elsif (my ($ext) = $file =~ /$SONG_REGEX/xms) { |
|
$t = Name_Torrent("$basedir/$ext"); |
|
$c = "$ext files from $basedir"; |
|
} |
|
|
|
$torrents{$t}{comment} = $c; |
|
push @{ $torrents{$t}{files} }, "$basedir/$file"; |
} |
} |
else { |
else { |
die "Invalid characters in file '$file' in '$basedir'"; |
die "Invalid characters in file '$file' in '$basedir'"; |
} |
} |
} |
} |
|
|
my $torrent = Name_Torrent($torrent_base); |
|
|
|
print "Creating $torrent\n"; |
foreach my $t (keys %torrents) { |
|
|
$comment .= "Created by andrew fresh (andrew\@afresh1.com)\n" . |
print "Creating $t (" |
"http://OpenBSD.somedomain.net/"; |
. (scalar @{ $torrents{$t}{files} }) . " files)\n"; |
|
|
eval { btmake($torrent, $comment, \@good_files); }; |
my $c = $torrents{$t}{comment}; |
if ($@) { |
$c .= "\nCreated by andrew fresh (andrew\@afresh1.com)\n" . |
print "Error creating $torrent\n$@\n"; |
"http://OpenBSD.somedomain.net/"; |
} |
|
|
|
|
eval { btmake($t, $c, $torrents{$t}{files}); }; |
|
if ($@) { |
|
print "Error creating $t\n$@\n"; |
|
} |
|
|
# system($BTMake, |
# system($BTMake, |
# '-C', |
# '-C', |
# '-c', $comment, |
# '-c', $comment, |
# '-n', $OBT->{BASENAME}, |
# '-n', $OBT->{BASENAME}, |
# '-o', $OBT->{DIR_TORRENT} . "/$torrent", |
# '-o', $OBT->{DIR_TORRENT} . "/$t", |
# '-a', $Tracker, |
# '-a', $Tracker, |
# @$files |
# @$files |
# );# || die "Couldn't system $BTMake $torrent: $!"; |
# );# || die "Couldn't system $BTMake $t: $!"; |
|
} |
|
|
return $torrent; |
return [ keys %torrents ]; |
} |
} |
|
|
|
|
|
|
#} |
#} |
$t->piece_length($piece_len); |
$t->piece_length($piece_len); |
$t->creation_date(time); |
$t->creation_date(time); |
print "Checksumming files. This may take a little while...\n"; |
#print "Checksumming files. This may take a little while...\n"; |
|
|
# Can't use this, have to do this manually because |
# Can't use this, have to do this manually because |
# we need to have the multi-file type of torrent |
# we need to have the multi-file type of torrent |