]> git.pld-linux.org Git - projects/distfiles.git/blame - request-handler.pl
Fix email headers formatting
[projects/distfiles.git] / request-handler.pl
CommitLineData
a04817ac 1#!/usr/bin/perl -w
052c958f
MM
2# read email with request from stdin and process it
3
631fa1b7
MM
4use Sys::Syslog;
5
6openlog("distfiles-rh", "pid", "user");
7
052c958f 8$spool_dir = "./spool";
7a0595ea 9$commits_list = "pld-cvs-commit\@lists.pld-linux.org";
052c958f
MM
10
11$spec = undef;
12$branch = "";
13$from = undef;
47f8fda7 14$flags = "";
052c958f 15
a04817ac 16# ---------------------------------------------------------------
91ff13d3 17use File::Basename;
95106fc3 18use File::Copy;
9654851f 19use Cwd;
91ff13d3 20
a04817ac
MM
21sub cleanup()
22{
23 system("rm -rf tmp/$id");
24}
25
26sub report_fatal($)
27{
28 my $msg = shift;
631fa1b7
MM
29
30 syslog("err","FATAL: $msg");
a04817ac 31 cleanup();
472da1da
JR
32
33 my $email_head =
34"From: $from <$from\@pld-linux.org>
a04817ac 35Subject: DISTFILES: ERROR fetching sources for $spec ($branch)
958ed10f 36X-distfiles-program: request-handler.pl";
472da1da
JR
37 my $email_body =
38"$msg
a04817ac
MM
39
40--
41Virtually Yours: distfiles.
472da1da
JR
42";
43
44 open(M, "| /usr/sbin/sendmail -t") or die("/usr/sbin/sendmail not found");
45 #open(M, "| cat") or die;
46 print M
47"To: $commits_list
48$email_head
49Message-ID: <$$." . time . "$id\@distfiles.pld-linux.org>
50
51$email_body";
52 close(M) or die("problem while sending email");
53
54 open(M, "| /usr/sbin/sendmail -t") or die("/usr/sbin/sendmail not found");
55 #open(M, "| cat") or die;
56 print M
57"To: <$from\@pld-linux.org>
58$email_head
59Message-ID: <$$." . time . "$id\@distfiles.pld-linux.org>
60
61$email_body";
b5160615 62 close(M) or die("problem while sending email");
a04817ac
MM
63 exit 0;
64}
65# ---------------------------------------------------------------
66
052c958f
MM
67$id = `uuidgen`;
68chomp $id;
69$id = rand if (!defined $id or $id eq "");
70
0e296d4e 71my $ref_pattern='[0-9a-zA-Z][0-9#a-zA-Z._\@/+ :,-]*';
052c958f 72while (<STDIN>) {
47f8fda7 73 chomp;
ad64e6a8 74 /^X-Package: ([a-z0-9_.+-]+)/i and $spec = $1;
0e296d4e 75 /^X-Branch: ($ref_pattern)/i and $branch = $1;
576dff03
ER
76 /^X-Login: ([a-z0-9_.]+)/i and $from = $1;
77 /^X-Flags: ([a-z0-9_ -]+)/i and $flags = $1;
052c958f
MM
78}
79
631fa1b7
MM
80if (!defined $from) {
81 syslog("err","FATAL: ill-formed request");
82 die "ill-formed request";
83}
84
85syslog("info","got request from $from for $spec at $branch ($flags)");
052c958f
MM
86
87report_fatal("bad spec name") if (!defined $spec);
88
d22382ac 89$oldcwd = Cwd::getcwd();
9654851f 90
b5160615 91mkdir("tmp/$id") or die("cannot create: tmp/$id");
052c958f
MM
92chdir("tmp/$id");
93
a106d34c 94my $cvs_get = `~/distfiles/show_spec.sh $spec $branch 2>&1`;
1f167206 95if ( $? ) {
d22382ac 96 chdir($oldcwd);
1f167206 97 my $at_branch = "";
98 $at_branch = " from branch $branch" if $branch;
99 my $code = $? >> 8;
ad64e6a8 100 report_fatal("cannot git fetch $spec$at_branch;\n$cvs_get\nexited with code $code");
052c958f
MM
101}
102
d22382ac 103chdir($oldcwd);
052c958f 104
631fa1b7 105syslog("info","spooling to tmp/$id/to-spool");
052c958f
MM
106open(S, "> tmp/$id/to-spool");
107print S "$from\@pld-linux.org\n";
cba859d3 108print S "$spec\n";
47f8fda7 109print S "$flags\n";
052c958f
MM
110close(S);
111
8b8c50a0 112if (system("perl ./specparser.pl \"tmp/$id/$spec\" tmp/$id/sources >> tmp/$id/to-spool") != 0) {
052c958f
MM
113 report_fatal("cannot parse $spec ($branch)")
114}
115
631fa1b7
MM
116if (!File::Copy::move("tmp/$id/to-spool", "$spool_dir/$id")) {
117 syslog("err","FATAL: move failed: $!");
118 die("move failed: $!");
119}
052c958f
MM
120
121cleanup();
122
123exit(0);
124
319fb6c1 125# vim: ts=2:sw=2:et
This page took 0.137228 seconds and 4 git commands to generate.