]> git.pld-linux.org Git - projects/distfiles.git/blame - request-handler.pl
- handle per-user upload directories
[projects/distfiles.git] / request-handler.pl
CommitLineData
052c958f
MM
1#!/usr/bin/perl
2# read email with request from stdin and process it
3
4$spool_dir = "./spool";
482655f9 5$commits_list = "pld-cvs-commit\@pld-linux.org";
052c958f
MM
6
7$spec = undef;
8$branch = "";
9$from = undef;
47f8fda7 10$flags = "";
052c958f
MM
11
12$id = `uuidgen`;
13chomp $id;
14$id = rand if (!defined $id or $id eq "");
15
16while (<STDIN>) {
47f8fda7 17 chomp;
052c958f
MM
18 /^X-Spec: ([\+a-zA-Z0-9_\-]+\.spec)/i and $spec = $1;
19 /^X-Branch: ([a-zA-Z0-9_\-]+)/i and $branch = $1;
20 /^X-Login: ([a-zA-Z0-9_]+)/i and $from = $1;
47f8fda7 21 /^X-Flags: ([a-zA-Z0-9\-_ ]+)/i and $flags = $1;
052c958f
MM
22}
23
24die "ill-formed request" if (!defined $from);
25
26report_fatal("bad spec name") if (!defined $spec);
27
28mkdir("tmp/$id") or die;
29chdir("tmp/$id");
30
31$branch = "" if ($branch eq "HEAD");
32$branch = "-r \"$branch\"" if ($branch ne "");
33
34if (system("cvs get $branch \"SPECS/$spec\" >/dev/null 2>&1") != 0) {
35 chdir("../..");
36 report_fatal("cannot cvs get $spec at $branch")
37}
38
39chdir("../..");
40
41open(S, "> tmp/$id/to-spool");
42print S "$from\@pld-linux.org\n";
47f8fda7 43print S "$flags\n";
052c958f
MM
44close(S);
45
06ea7f33 46if (system("perl ./specparser.pl \"tmp/$id/SPECS/$spec\" >> tmp/$id/to-spool") != 0) {
052c958f
MM
47 report_fatal("cannot parse $spec ($branch)")
48}
49
50rename("tmp/$id/to-spool", "$spool_dir/$id");
51
52cleanup();
53
54exit(0);
55
56sub report_fatal($)
57{
58 my $msg = shift;
59 cleanup();
9a1e36f3
MM
60 open(M, "| /usr/sbin/sendmail -t") or die;
61 #open(M, "| cat") or die;
052c958f
MM
62 my $version = '$Id$';
63 print M <<EOF
04550b88 64From: $from <$from\@pld-linux.org>
482655f9
MM
65To: $commits_list
66Cc: $from\@pld-linux.org
052c958f 67Message-ID: <$id\@distfiles.pld-linux.org>
04550b88 68Subject: DISTFILES: ERROR fetching sources for $spec ($branch)
052c958f
MM
69X-distfiles-program: request-handler.pl
70X-distfiles-version: $version
71
72$msg
73
74--
d8cd573c 75Virtually Yours: distfiles.
052c958f
MM
76EOF
77;
78 close(M) or die;
79 exit 0;
80}
81
82sub cleanup()
83{
84 system("rm -rf tmp/$id");
85}
This page took 0.193228 seconds and 4 git commands to generate.