-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-rc-tarball.pl
executable file
·134 lines (117 loc) · 4.12 KB
/
get-rc-tarball.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env perl
use 5.14.0;
use warnings;
use Data::Dumper;$Data::Dumper::Indent=1;
use Data::Dump ( qw| dd pp| );
use Carp;
use Getopt::Long;
use Perl::Download::FTP;
use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Simple::Creator;
=head1 USAGE
perl get-rc-tarball.pl \
--host=ftp.cpan.org \
--hostdir=/pub/CPAN/src/5.0 \
--compression=gz \
--type=dev_or_rc \
--dev_cycle=29 \
--downloads_dir=$DOWNLOADS_DIR \
--email_to='"James E Keenan" <[email protected]>' \
--email_from='"James E Keenan" <[email protected]>' \
--email_subject='Status of Perl 5 RC release' \
--verbose
=cut
my $date = qx/date/;
chomp $date;
say sprintf("%-52s%s" => ("Date:", $date));
say "Running $0";
my ($host, $hostdir, $verbose, $compression, $type, $dev_cycle, $downloads_dir) = ('') x 6;
my ($email_from, $email_to, $email_subject) = (undef) x 3;
GetOptions(
"host=s" => \$host,
"hostdir=s" => \$hostdir,
"compression=s" => \$compression,
"type=s" => \$type,
"dev_cycle=i" => \$dev_cycle,
"downloads_dir=s" => \$downloads_dir,
"email_from=s" => \$email_from,
"email_to=s" => \$email_to,
"email_subject=s" => \$email_subject,
"verbose" => \$verbose,
) or croak "Unable to get options";
croak "Unable to locate downloads_dir" unless (-d $downloads_dir);
say "host: $host" if $verbose;
say "hostdir: $hostdir" if $verbose;
say "compression: $compression" if $verbose;
say "type: $type" if $verbose;
say "dev_cycle: $dev_cycle" if $verbose;
my ($minor_version, $rc_version);
$minor_version = $dev_cycle;
$rc_version = $minor_version + 1;
my $pdfobj = Perl::Download::FTP->new( {
host => $host,
dir => $hostdir,
verbose => $verbose,
Passive => 1,
} );
#dd($pdfobj);
croak "Unable to create object" unless defined $pdfobj;
my @all_releases = $pdfobj->ls();
my @releases = grep { m/perl-5\.($minor_version|$rc_version)/ }
$pdfobj->list_releases( {
type => $type,
compression => $compression,
} ) or croak "Wrong " . $pdfobj->{ftp}->message;
if ($verbose) {
say "We can see these dev_or_rc versions on server";
dd(\@releases);
}
my $latest_on_server = $releases[0];
say "latest_on_server: $latest_on_server" if $verbose;
my $email_body;
if ($latest_on_server =~ m/RC/) {
say "Downloading RC release $latest_on_server" if $verbose;
my $specific_release = $pdfobj->get_specific_release( {
release => $latest_on_server,
path => $downloads_dir,
} );
say "Downloaded: $specific_release" if $verbose;
$email_body = "We have downloaded $latest_on_server to $specific_release";
email_notify( {
email_to => $email_to,
email_from => $email_from,
email_subject => $email_subject,
latest_on_server => $latest_on_server,
email_body => $email_body,
} );
}
else {
say "Most recent release in dev_cycle $dev_cycle, $latest_on_server, is not an RC release" if $verbose;
$email_body = "Most recent release in dev_cycle $dev_cycle, $latest_on_server, is not an RC release";
email_notify( {
email_to => $email_to,
email_from => $email_from,
email_subject => $email_subject,
latest_on_server => $latest_on_server,
email_body => $email_body,
} );
}
say "Finished!" if $verbose;
exit 0;
sub email_notify {
my $args = shift;
croak "email_notify() takes hash reference" unless ref($args) eq 'HASH';
my $email = Email::Simple->create(
header => [
To => $args->{email_to},
From => $args->{email_from},,
Subject => join(' ' => ($args->{email_subject}, $args->{latest_on_server})),
],
body => $args->{email_body},
);
local $@;
eval { sendmail($email); };
if ($@) { say "Problem in sending email: <$@>"; exit 1; }
else { return 1 };
}