]>
Commit | Line | Data |
---|---|---|
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 | 14 | use File::Basename; |
95106fc3 | 15 | use File::Copy; |
9654851f | 16 | use Cwd; |
91ff13d3 | 17 | |
a04817ac MM |
18 | sub cleanup() |
19 | { | |
20 | system("rm -rf tmp/$id"); | |
21 | } | |
22 | ||
23 | sub report_fatal($) | |
24 | { | |
25 | my $msg = shift; | |
26 | cleanup(); | |
2fcadf85 | 27 | open(M, "| /usr/sbin/sendmail -t") or die("/usr/sbin/sendmail not found"); |
a04817ac MM |
28 | #open(M, "| cat") or die; |
29 | my $version = '$Id$'; | |
30 | print M <<EOF | |
31 | From: $from <$from\@pld-linux.org> | |
32 | To: $commits_list | |
33 | Cc: $from\@pld-linux.org | |
34 | Message-ID: <$id\@distfiles.pld-linux.org> | |
35 | Subject: DISTFILES: ERROR fetching sources for $spec ($branch) | |
36 | X-distfiles-program: request-handler.pl | |
37 | X-distfiles-version: $version | |
38 | ||
39 | $msg | |
40 | ||
41 | -- | |
42 | Virtually Yours: distfiles. | |
43 | EOF | |
44 | ; | |
b5160615 | 45 | close(M) or die("problem while sending email"); |
a04817ac MM |
46 | exit 0; |
47 | } | |
48 | # --------------------------------------------------------------- | |
49 | ||
052c958f MM |
50 | $id = `uuidgen`; |
51 | chomp $id; | |
52 | $id = rand if (!defined $id or $id eq ""); | |
53 | ||
54 | while (<STDIN>) { | |
47f8fda7 | 55 | chomp; |
ad64e6a8 KK |
56 | /^X-Package: ([a-z0-9_.+-]+)/i and $spec = $1; |
57 | /^X-Branch: ([\/a-z0-9_-]+)/i and $branch = $1; | |
576dff03 ER |
58 | /^X-Login: ([a-z0-9_.]+)/i and $from = $1; |
59 | /^X-Flags: ([a-z0-9_ -]+)/i and $flags = $1; | |
052c958f MM |
60 | } |
61 | ||
62 | die "ill-formed request" if (!defined $from); | |
63 | ||
64 | report_fatal("bad spec name") if (!defined $spec); | |
65 | ||
d22382ac | 66 | $oldcwd = Cwd::getcwd(); |
9654851f | 67 | |
b5160615 | 68 | mkdir("tmp/$id") or die("cannot create: tmp/$id"); |
052c958f MM |
69 | chdir("tmp/$id"); |
70 | ||
ad64e6a8 | 71 | my $cvs_get = `~/show_spec.sh $spec $branch 2>&1`; |
1f167206 | 72 | if ( $? ) { |
d22382ac | 73 | chdir($oldcwd); |
1f167206 | 74 | my $at_branch = ""; |
75 | $at_branch = " from branch $branch" if $branch; | |
76 | my $code = $? >> 8; | |
ad64e6a8 | 77 | report_fatal("cannot git fetch $spec$at_branch;\n$cvs_get\nexited with code $code"); |
052c958f MM |
78 | } |
79 | ||
d22382ac | 80 | chdir($oldcwd); |
052c958f MM |
81 | |
82 | open(S, "> tmp/$id/to-spool"); | |
83 | print S "$from\@pld-linux.org\n"; | |
cba859d3 | 84 | print S "$spec\n"; |
47f8fda7 | 85 | print S "$flags\n"; |
052c958f MM |
86 | close(S); |
87 | ||
ad64e6a8 | 88 | if (system("perl ./specparser.pl \"tmp/$id/$spec\" >> tmp/$id/to-spool") != 0) { |
052c958f MM |
89 | report_fatal("cannot parse $spec ($branch)") |
90 | } | |
91 | ||
95106fc3 | 92 | File::Copy::move("tmp/$id/to-spool", "$spool_dir/$id") or die("move failed: $!"); |
052c958f MM |
93 | |
94 | cleanup(); | |
95 | ||
96 | exit(0); | |
97 | ||
319fb6c1 | 98 | # vim: ts=2:sw=2:et |