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