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