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