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";
21 # try lookup some file in spool, exit if it cannot be done
22 sub find_file_in_spool()
24 opendir(DIR, $spool_dir) || die "can't opendir $spool_dir: $!";
28 -f "$spool_dir/$f" or next;
29 $file = "$spool_dir/$f";
34 exit 0 if ($file eq "");
37 # read file from spool, and try unlink it. if cannot unlink -- exit
38 # sets $requester (email), $problems, @md5 (arrays of md5's)
39 # and %url (map from md5 to urls)
42 open(F, "< $file") || exit 0;
45 $requester =~ /^[a-zA-Z_\-0-9\@\.]+$/
46 or die "$file: evil requester: $requester";
48 $force_reply++ if ($flags =~ /force-reply/);
56 /^([a-f0-9]{32})\s+((ftp|http|no-url|no-url-copy):\/\/([a-z0-9A-Z:\+\~\.\-\/_]|\%[0-9])+)\s*$/
57 or die "$file: corrupted";
60 /\/$/ and die "$file: cannot fetch dir";
64 unlink($file) || exit 0;
78 return "$ftp_dir/by-md5/$1/$2/$md5/" . basename($url);
85 $dir =~ /(.*)\/[^\/]+$/ and install_dir($1);
91 my ($md5, $url, $local_copy) = @_;
93 my $path = file_path($md5, $url);
95 $path =~ /(.*)\/[^\/]+$/ and install_dir($1);
97 if (system("mv -f \"$local_copy\" \"$path\"")) {
98 $problems .= "FATAL: cannot mv file ($url)\n";
100 if (open(D, "> $path.desc")) {
101 print D "URL: $url\n";
102 print D "MD5: $md5\n";
103 print D 'Fetched-by: $Id$'."\n";
104 print D "Time: " . time . "\n";
107 $problems .= "ERROR: cannot write $path.desc\n";
111 $md5 =~ /^(..)/ and my $m2 = $1;
113 if (open(L, ">> $ENV{HOME}/.lists/lista_$m2")) {
114 print L "/home/ftp/pub/Linux/distfiles/by-md5/$1/$2/$md5/" . basename($url) . "\n";
120 "\t$md5 " . basename($url) . "\n" .
121 "\tSize: " . (-s $path) . " bytes\n";
126 sub make_src_symlink($$)
128 my ($md5, $url) = @_;
129 my $path = file_path($md5, $url);
130 $path =~ s/.*?by-md5/..\/by-md5/;
131 $url =~ m|://([^/]+)| or die "corrupted! (no-url, copy)";
133 my $symlink = "$ftp_dir/$copy_dir/$basename";
135 my $old = readlink $symlink;
137 if ($url =~ /^no-url-copy/) {
138 symlink($path, $symlink);
140 $normal_out .= "Made symlink in src/ for $basename\n";
142 } elsif ($url =~ /^no-url-copy/) {
145 symlink($path, $symlink);
146 $problems .= "WARNING: $symlink already existed with value $old, set to $path\n";
148 $normal_out .= "Symlink in src/ for $basename already there\n";
152 $problems .= "WARNING: Removed symlink $symlink\n";
159 my $md5 = `md5sum "$file" 2>/dev/null`;
160 $md5 =~ /^([a-f0-9]{32})/ and $md5 = $1;
164 sub handle_no_url($$)
166 my ($md5, $url) = @_;
168 $url =~ m|://([^/]+)| or die "corrupted! (no-url)";
170 my $file = "$no_url_dir/$basename";
173 my $computed_md5 = md5($file);
174 if ($computed_md5 ne $md5) {
175 $problems .= "FATAL: $file md5 mismatch, needed $md5, got $computed_md5\n";
177 move_file($md5, $url, $file);
178 make_src_symlink($md5, $url);
181 $problems .= "FATAL: $file was not scp'ed\n";
187 my ($md5, $url) = @_;
189 my $cmd = "wget -nv -O tmp/$md5 \"$url\"";
191 push @files, basename($url);
193 my $path = file_path($md5, $url);
196 "ALREADY GOT: $url\n" .
197 "\t$md5 " . basename($url) . "\n" .
198 "\tSize: " . (-s $path) . " bytes.\n";
199 make_src_symlink($md5, $url);
203 if ($url =~ /^no-url/) {
204 handle_no_url($md5, $url);
208 open(W, "$cmd 2>&1 |");
210 /URL:.*\s+\-\>\s+.*/ and next;
215 $problems .= "$cmd:\n$out\n\n";
217 if (-f "tmp/$md5" && -s "tmp/$md5" > 0) {
218 my $computed_md5 = md5("tmp/$md5");
219 if ($computed_md5 ne $md5) {
220 $problems .= "FATAL: $url md5 mismatch, needed $md5, got $computed_md5\n";
222 move_file($md5, $url, "tmp/$md5");
225 $problems .= "FATAL: $url ($md5) was not fetched\n";
232 $problems .= "\n\n" if ($problems ne "");
233 foreach $md5 (@md5) {
234 fetch_file($md5, $url{$md5});
240 open(EMAIL, "| /usr/sbin/sendmail -t");
241 #open(EMAIL, "| cat");
243 if ($problems ne "") {
244 $marker = "ERRORS: ";
247 $requester =~ /^(.*)\@/ and $req_login = $1;
249 splice(@files, 10, @files - 10, "...")
253 "From: $req_login <$requester>
256 Subject: DISTFILES: ${marker}@{files}
257 Message-ID: <$$." . time . "\@distfiles.pld-linux.org>
258 X-distfiles-program: file-fetcher.pl
259 X-distfiles-version: " . '$Id$' . "
262 Files fetched: $fetched_count
267 Virtually Yours: distfiles.
272 find_file_in_spool();
275 send_email() unless (!$force_reply and $problems eq "" and $fetched_count == 0);