4 $commits_list = "pld-cvs-commit\@pld-linux.org";
6 $spool_dir = "./spool";
8 $copy_dir = "src"; # relative to $ftp_dir
9 $no_url_dir = "./plddfadd";
19 $req_login = "nobody";
22 # try lookup some file in spool, exit if it cannot be done
23 sub find_file_in_spool()
25 opendir(DIR, $spool_dir) || die "can't opendir $spool_dir: $!";
29 -f "$spool_dir/$f" or next;
30 $file = "$spool_dir/$f";
35 exit 0 if ($file eq "");
38 # read file from spool, and try unlink it. if cannot unlink -- exit
39 # sets $requester (email), $problems, @md5 (arrays of md5's)
40 # and %url (map from md5 to urls)
43 open(F, "< $file") || exit 0;
46 $requester =~ /^[a-zA-Z_\-0-9\@\.]+$/
47 or die "$file: evil requester: $requester";
49 $requester =~ /^([^@]+)\@/ and $req_login = $1;
50 $req_login =~ /^[a-z0-9A-Z_]+$/ or die "$file: evil requester $requester";
52 $force_reply++ if ($flags =~ /force-reply/);
60 /^([a-f0-9]{32})\s+((ftp|http|no-url|no-url-copy):\/\/([a-z0-9A-Z:\+\~\.\-\/_]|\%[0-9])+)\s*$/
61 or die "$file: corrupted";
64 /\/$/ and die "$file: cannot fetch dir";
68 unlink($file) || exit 0;
82 return "$ftp_dir/by-md5/$1/$2/$md5/" . basename($url);
89 $dir =~ /(.*)\/[^\/]+$/ and install_dir($1);
95 my ($md5, $url, $local_copy) = @_;
97 my $path = file_path($md5, $url);
99 $path =~ /(.*)\/[^\/]+$/ and install_dir($1);
101 if (system("mv -f \"$local_copy\" \"$path\"")) {
102 $problems .= "FATAL: cannot mv file ($url)\n";
104 if (open(D, "> $path.desc")) {
105 print D "URL: $url\n";
106 print D "MD5: $md5\n";
107 print D 'Fetched-by: $Id$'."\n";
108 print D "Time: " . time . "\n";
111 $problems .= "ERROR: cannot write $path.desc\n";
115 $md5 =~ /^(..)/ and my $m2 = $1;
117 if (open(L, ">> $ENV{HOME}/.lists/lista_$m2")) {
118 print L "/home/ftp/pub/Linux/distfiles/by-md5/$1/$2/$md5/" . basename($url) . "\n";
124 "\t$md5 " . basename($url) . "\n" .
125 "\tSize: " . (-s $path) . " bytes\n";
130 sub make_src_symlink($$)
132 my ($md5, $url) = @_;
133 my $path = file_path($md5, $url);
134 $path =~ s/.*?by-md5/..\/by-md5/;
135 $url =~ m|://([^/]+)| or die "corrupted! (no-url, copy)";
137 my $symlink = "$ftp_dir/$copy_dir/$basename";
139 my $old = readlink $symlink;
141 if ($url =~ /^no-url-copy/) {
142 symlink($path, $symlink);
144 $normal_out .= "Made symlink in src/ for $basename\n";
146 } elsif ($url =~ /^no-url-copy/) {
149 symlink($path, $symlink);
150 $problems .= "WARNING: $symlink already existed with value $old, set to $path\n";
152 $normal_out .= "Symlink in src/ for $basename already there\n";
156 $problems .= "WARNING: Removed symlink $symlink\n";
163 my $md5 = `md5sum "$file" 2>/dev/null`;
164 $md5 =~ /^([a-f0-9]{32})/ and $md5 = $1;
168 sub handle_no_url($$)
170 my ($md5, $url) = @_;
172 $url =~ m|://([^/]+)| or die "corrupted! (no-url)";
174 my $file = "$no_url_dir/$req_login/$basename";
177 my $computed_md5 = md5($file);
178 if ($computed_md5 ne $md5) {
179 $problems .= "FATAL: $file md5 mismatch, needed $md5, got $computed_md5\n";
181 move_file($md5, $url, $file);
182 make_src_symlink($md5, $url);
185 $problems .= "FATAL: $file was not uploaded\n";
191 my ($md5, $url) = @_;
193 my $cmd = "wget -nv -O tmp/$md5 \"$url\"";
195 push @files, basename($url);
197 my $path = file_path($md5, $url);
200 "ALREADY GOT: $url\n" .
201 "\t$md5 " . basename($url) . "\n" .
202 "\tSize: " . (-s $path) . " bytes.\n";
203 make_src_symlink($md5, $url);
207 if ($url =~ /^no-url/) {
208 handle_no_url($md5, $url);
212 open(W, "$cmd 2>&1 |");
214 /URL:.*\s+\-\>\s+.*/ and next;
219 $problems .= "$cmd:\n$out\n\n";
221 if (-f "tmp/$md5" && -s "tmp/$md5" > 0) {
222 my $computed_md5 = md5("tmp/$md5");
223 if ($computed_md5 ne $md5) {
224 $problems .= "FATAL: $url md5 mismatch, needed $md5, got $computed_md5\n";
226 move_file($md5, $url, "tmp/$md5");
229 $problems .= "FATAL: $url ($md5) was not fetched\n";
236 $problems .= "\n\n" if ($problems ne "");
237 foreach $md5 (@md5) {
238 fetch_file($md5, $url{$md5});
244 open(EMAIL, "| /usr/sbin/sendmail -t");
245 #open(EMAIL, "| cat");
247 if ($problems ne "") {
248 $marker = "ERRORS: ";
251 $requester =~ /^(.*)\@/ and $req_login = $1;
253 splice(@files, 10, @files - 10, "...")
257 "From: $req_login <$requester>
260 Subject: DISTFILES: ${marker}@{files}
261 Message-ID: <$$." . time . "\@distfiles.pld-linux.org>
262 X-distfiles-program: file-fetcher.pl
263 X-distfiles-version: " . '$Id$' . "
266 Files fetched: $fetched_count
271 Virtually Yours: distfiles.
276 find_file_in_spool();
279 send_email() unless (!$force_reply and $problems eq "" and $fetched_count == 0);