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