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