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