version 1.2, 2005/03/22 23:44:43 |
version 1.5, 2005/03/25 03:11:38 |
|
|
|
|
our @EXPORT = qw( |
our @EXPORT = qw( |
$BaseDir |
$BaseDir |
|
$HomeDir |
$TorrentDir |
$TorrentDir |
$BaseName |
$BaseName |
$Tracker |
$Tracker |
&Name_Torrent |
&Name_Torrent |
&Get_Files_and_Dirs |
&Get_Files_and_Dirs |
|
&justme |
); |
); |
|
|
our $BaseDir = '/home/ftp/pub'; |
our $BaseDir = '/home/ftp/pub'; |
our $TorrentDir = '/home/andrew/torrents'; |
our $HomeDir = '/home/andrew/OpenBSDTorrents'; |
our $BaseName = 'OpenBSD'; |
our $TorrentDir = '/home/andrew/torrents'; |
our $Tracker = 'http://OpenBSD.somedomain.net/announce.php'; |
our $BaseName = 'OpenBSD'; |
|
our $Tracker = 'http://OpenBSD.somedomain.net/announce.php'; |
|
|
# These are regexes that tell what files to skip; |
# These are regexes that tell what files to skip; |
our $SkipDirs = qr/\/patches$/; |
our $SkipDirs = qr/\/patches$/; |
|
|
{ |
{ |
my $basedir = shift; |
my $basedir = shift; |
opendir DIR, $basedir or die "Couldn't opendir $basedir: $!"; |
opendir DIR, $basedir or die "Couldn't opendir $basedir: $!"; |
my @contents = grep { ! /^\.\.$/ } grep { ! /^\.$/ } readdir DIR; |
my @contents = sort grep { ! /^\.\.$/ } grep { ! /^\.$/ } readdir DIR; |
closedir DIR; |
closedir DIR; |
my @dirs = grep { -d "$basedir/$_" } @contents; |
my @dirs = grep { -d "$basedir/$_" } @contents; |
|
|
|
|
} |
} |
return join '-', ($year, $mon, $mday, $hour . $min); |
return join '-', ($year, $mon, $mday, $hour . $min); |
} |
} |
|
|
|
# "There can be only one." --the Highlander |
|
sub justme { |
|
|
|
my $myname; |
|
|
|
if ($0 =~ m#([^/]+$)#) { |
|
$myname = $1; |
|
} else { |
|
die "Couldn't figure out myname"; |
|
} |
|
|
|
my $SEMA = "$HomeDir/$myname.pid"; |
|
if (open SEMA, "<", $SEMA) { |
|
my $pid = <SEMA>; |
|
if (defined $pid) { |
|
chomp $pid; |
|
if ($pid =~ /^(\d+)$/) { |
|
$pid = $1; |
|
} else { |
|
die "invalid pid read '$pid'"; |
|
} |
|
if (kill(0, $pid)) { |
|
print "$0 already running (pid $pid), bailing out\n"; |
|
exit 253; |
|
} |
|
} |
|
close SEMA; |
|
} |
|
open (SEMA, ">", $SEMA) or die "can't write $SEMA: $!"; |
|
print SEMA "$$\n"; |
|
close(SEMA) or die "can't close $SEMA: $!"; |
|
} |
|
|
|
|
1; |
1; |
__END__ |
__END__ |