1 |
gvacanti |
1.1 |
#!/usr/local/bin/perl |
2 |
|
|
# |
3 |
|
|
# uploadccf |
4 |
|
|
|
5 |
|
|
BEGIN { |
6 |
|
|
my $fail = 0; |
7 |
|
|
my @mods = qw(Net::FTP Mail::Send); |
8 |
|
|
foreach (@mods) { |
9 |
|
|
unless (eval "require $_") { |
10 |
|
|
warn "Could not find required module $_: $@.\n"; |
11 |
|
|
$fail++; |
12 |
|
|
} |
13 |
|
|
} |
14 |
|
|
die "Some of the required modules could not be found.\n"if $fail; |
15 |
|
|
} |
16 |
|
|
|
17 |
|
|
|
18 |
|
|
require 5.001; |
19 |
|
|
|
20 |
|
|
$VERSION = "0.3"; |
21 |
|
|
|
22 |
|
|
use Getopt::Long; |
23 |
|
|
|
24 |
|
|
=head1 NAME |
25 |
|
|
|
26 |
|
|
uploadccf - |
27 |
|
|
|
28 |
|
|
=head1 SYNOPSIS |
29 |
|
|
|
30 |
|
|
uploadccf package ... |
31 |
|
|
|
32 |
|
|
=head1 DESCRIPTION |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
=head1 EXAMPLES |
36 |
|
|
|
37 |
|
|
=over 4 |
38 |
|
|
|
39 |
|
|
=item * |
40 |
|
|
|
41 |
|
|
Submit packages foo-1.2.tgz and bar-2.4.tgz |
42 |
|
|
|
43 |
|
|
C< uploadsas foo-1.2.tgz bar-2.4.tgz> |
44 |
|
|
|
45 |
|
|
=back |
46 |
|
|
|
47 |
|
|
=head1 AUTHOR |
48 |
|
|
|
49 |
|
|
Giuseppe Vacanti <gvacanti@astro.estec.esa.nl> |
50 |
|
|
|
51 |
|
|
=cut |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
# Configure these for the remote FTP server: |
55 |
|
|
$server = "astro.estec.esa.nl"; |
56 |
|
|
$remote_dir = "/pub/ccflib/private/incoming/"; |
57 |
|
|
$user = "anonymous"; |
58 |
|
|
|
59 |
|
|
$ccflib = 'ccflib@astro.estec.esa.nl'; |
60 |
|
|
|
61 |
|
|
# Get program name |
62 |
|
|
$progname = $0; |
63 |
|
|
$progname =~ s/.*\///; |
64 |
|
|
|
65 |
|
|
# Process each ".tgz" file in turn |
66 |
|
|
my @flist; |
67 |
|
|
|
68 |
|
|
foreach(@ARGV){ |
69 |
|
|
if(/-v/){ |
70 |
|
|
print "$progname - $VERSION\n"; |
71 |
|
|
exit(0); |
72 |
|
|
} |
73 |
|
|
if(-r){ |
74 |
|
|
if(! /.+\.tgz/){ |
75 |
|
|
warn("$_ is not a package and it'll be ignored.\n"); |
76 |
|
|
next; |
77 |
|
|
} |
78 |
|
|
push @flist, $_; |
79 |
|
|
} else { |
80 |
|
|
warn("$_ cannot be read.\n"); |
81 |
|
|
} |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
die "No files to transfer.\n" unless @flist; |
85 |
|
|
|
86 |
|
|
my $ftp = Net::FTP->new("$server") or die "Cannot connect to $server: $!\n"; |
87 |
|
|
$ftp->login($user) or die "Cannot login as $user: $!\n"; |
88 |
|
|
$ftp->binary(); |
89 |
|
|
$ftp->cwd($remote_dir) or die "Cannot change directory to $remote_dir: $!\n";; |
90 |
|
|
my @oklist; |
91 |
|
|
|
92 |
|
|
foreach(@flist){ |
93 |
|
|
$ftp->put($_) ? push @oklist, $_ : warn("Could not tranfer $_: $!\n"); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
my $msg = Mail::Send->new( |
97 |
gvacanti |
1.2 |
Subject => "CCF package upload: @oklist", |
98 |
gvacanti |
1.1 |
To => $ccflib, |
99 |
|
|
); |
100 |
|
|
my $fh = $msg->open(); |
101 |
|
|
print $fh "\nThe following files were uploaded to $server:\n"; |
102 |
|
|
foreach (@oklist) { |
103 |
|
|
$_ =~ s/^.*\///; |
104 |
|
|
print $fh " $_\n"; |
105 |
|
|
} |
106 |
|
|
$fh->close(); |
107 |
|
|
print "Notification message sent to $ccflib\n"; |