4 $email_cc = "pld-cvs-commits\@pld-linux.org";
6 $spool_dir = "./spool";
8 $copy_dir = "src"; # relative to $ftp_dir
9 $no_url_dir = "./plddfadd";
20 # try lookup some file in spool, exit if it cannot be done
21 sub find_file_in_spool()
23 opendir(DIR, $spool_dir) || die "can't opendir $spool_dir: $!";
27 -f "$spool_dir/$f" or next;
28 $file = "$spool_dir/$f";
33 exit 0 if ($file eq "");
36 # read file from spool, and try unlink it. if cannot unlink -- exit
37 # sets $requester (email), $problems, @md5 (arrays of md5's)
38 # and %url (map from md5 to urls)
41 open(F, "< $file") || exit 0;
44 $requester =~ /^[a-zA-Z_\-0-9\@\.]+$/
45 or die "$file: evil requester: $requester";
47 $force_reply++ if ($flags =~ /force-reply/);
55 /^([a-f0-9]{32})\s+((ftp|http|no-url|no-url-copy):\/\/([a-z0-9A-Z:\+\~\.\-\/_]|\%[0-9])+)\s*$/
56 or die "$file: corrupted";
59 /\/$/ and die "$file: cannot fetch dir";
63 unlink($file) || exit 0;
71 my $md5_dir = "$ftp_dir/by-md5/$1/$2/$md5";
72 $url =~ /\/([^\/]+)$/ or die;
74 return "$md5_dir/$basename";
81 $dir =~ /(.*)\/[^\/]+$/ and install_dir($1);
87 my ($md5, $url, $local_copy) = @_;
89 my $path = file_path($md5, $url);
91 $path =~ /(.*)\/[^\/]+$/ and install_dir($1);
93 if (system("mv -f \"$local_copy\" \"$path\"")) {
94 $problems .= "FATAL: cannot mv file ($url)\n";
96 if (open(D, "> $path.desc")) {
97 print D "URL: $url\n";
98 print D "MD5: $md5\n";
99 print D 'Fetched-by: $Id$'."\n";
100 print D "Time: " . time . "\n";
103 $problems .= "ERROR: cannot write $path.desc\n";
107 $md5 =~ /^(..)/ and my $m2 = $1;
109 if (open(L, ">> $ENV{HOME}/.lists/lista_$m2")) {
110 print L "/home/ftp/pub/Linux/distfiles/by-md5/$1/$2/$md5/";
111 $url =~ /\/([^\/]+)$/;
116 $normal_out .= "STORED: $url ($md5, " . (-s $path) . " bytes)\n";
121 sub make_src_symlink($$)
123 my ($md5, $url) = @_;
124 my $path = file_path($md5, $url);
125 $path =~ s/.*?by-md5/..\/by-md5/;
126 $url =~ m|://([^/]+)| or die "corrupted! (no-url, copy)";
128 my $symlink = "$ftp_dir/$copy_dir/$basename";
130 my $old = readlink $symlink;
132 if ($url =~ /^no-url-copy/) {
133 symlink($path, $symlink);
135 $normal_out .= "Made symlink in src/ for $basename\n";
137 } elsif ($url =~ /^no-url-copy/) {
140 symlink($path, $symlink);
141 $problems .= "WARNING: $symlink already existed with value $old, set to $path\n";
143 $normal_out .= "Symlink in src/ for $basename already there\n";
147 $problems .= "WARNING: Removed symlink $symlink\n";
154 my $md5 = `md5sum "$file" 2>/dev/null`;
155 $md5 =~ /^([a-f0-9]{32})/ and $md5 = $1;
159 sub handle_no_url($$)
161 my ($md5, $url) = @_;
163 $url =~ m|://([^/]+)| or die "corrupted! (no-url)";
165 my $file = "$no_url_dir/$basename";
168 my $computed_md5 = md5($file);
169 if ($computed_md5 ne $md5) {
170 $problems .= "FATAL: $file md5 mismatch, needed $md5, got $computed_md5\n";
172 move_file($md5, $url, $file);
173 make_src_symlink($md5, $url);
176 $problems .= "FATAL: $file was not scp'ed\n";
182 my ($md5, $url) = @_;
184 my $cmd = "wget -nv -O tmp/$md5 \"$url\"";
186 my $path = file_path($md5, $url);
188 $normal_out .= "ALREADY GOT: $url ($md5, " . (-s $path) . " bytes)\n";
189 make_src_symlink($md5, $url);
193 if ($url =~ /^no-url/) {
194 handle_no_url($md5, $url);
198 open(W, "$cmd 2>&1 |");
200 /URL:.*\s+\-\>\s+.*/ and next;
205 $problems .= "$cmd:\n$out\n\n";
207 if (-f "tmp/$md5" && -s "tmp/$md5" > 0) {
208 my $computed_md5 = md5("tmp/$md5");
209 if ($computed_md5 ne $md5) {
210 $problems .= "FATAL: $url md5 mismatch, needed $md5, got $computed_md5\n";
212 move_file($md5, $url, "tmp/$md5");
215 $problems .= "FATAL: $url ($md5) was not fetched\n";
222 $problems .= "\n\n" if ($problems ne "");
223 foreach $md5 (@md5) {
224 fetch_file($md5, $url{$md5});
230 open(EMAIL, "| /usr/sbin/sendmail -t");
231 #open(EMAIL, "| cat");
233 if ($problems ne "") {
237 "From: distfiles <feedback\@pld-linux.org>
240 Subject: [distfiles] sources fetched $marker
241 Message-ID: <$$." . time . "\@distfiles.pld-linux.org>
242 X-distfiles-program: file-fetcher.pl
243 X-distfiles-version: " . '$Id$' . "
246 Files fetched: $fetched_count
251 Virtually Yours: distfiles.
256 find_file_in_spool();
259 send_email() unless (!$force_reply and $problems eq "" and $fetched_count == 0);