]>
Commit | Line | Data |
---|---|---|
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 | use File::Basename; | |
15 | use File::Copy; | |
16 | use Cwd; | |
17 | ||
18 | sub cleanup() | |
19 | { | |
20 | system("rm -rf tmp/$id"); | |
21 | } | |
22 | ||
23 | sub report_fatal($) | |
24 | { | |
25 | my $msg = shift; | |
26 | cleanup(); | |
27 | open(M, "| /usr/sbin/sendmail -t") or die("/usr/sbin/sendmail not found"); | |
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 | ; | |
45 | close(M) or die("problem while sending email"); | |
46 | exit 0; | |
47 | } | |
48 | # --------------------------------------------------------------- | |
49 | ||
50 | $id = `uuidgen`; | |
51 | chomp $id; | |
52 | $id = rand if (!defined $id or $id eq ""); | |
53 | ||
54 | my $ref_pattern='[0-9a-zA-Z][0-9#a-zA-Z._\@/+ :,-]*'; | |
55 | while (<STDIN>) { | |
56 | chomp; | |
57 | /^X-Package: ([a-z0-9_.+-]+)/i and $spec = $1; | |
58 | /^X-Branch: ($ref_pattern)/i and $branch = $1; | |
59 | /^X-Login: ([a-z0-9_.]+)/i and $from = $1; | |
60 | /^X-Flags: ([a-z0-9_ -]+)/i and $flags = $1; | |
61 | } | |
62 | ||
63 | die "ill-formed request" if (!defined $from); | |
64 | ||
65 | report_fatal("bad spec name") if (!defined $spec); | |
66 | ||
67 | $oldcwd = Cwd::getcwd(); | |
68 | ||
69 | mkdir("tmp/$id") or die("cannot create: tmp/$id"); | |
70 | chdir("tmp/$id"); | |
71 | ||
72 | my $cvs_get = `~/distfiles/show_spec.sh $spec $branch 2>&1`; | |
73 | if ( $? ) { | |
74 | chdir($oldcwd); | |
75 | my $at_branch = ""; | |
76 | $at_branch = " from branch $branch" if $branch; | |
77 | my $code = $? >> 8; | |
78 | report_fatal("cannot git fetch $spec$at_branch;\n$cvs_get\nexited with code $code"); | |
79 | } | |
80 | ||
81 | chdir($oldcwd); | |
82 | ||
83 | open(S, "> tmp/$id/to-spool"); | |
84 | print S "$from\@pld-linux.org\n"; | |
85 | print S "$spec\n"; | |
86 | print S "$flags\n"; | |
87 | close(S); | |
88 | ||
89 | if (system("perl ./specparser.pl \"tmp/$id/$spec\" >> tmp/$id/to-spool") != 0) { | |
90 | report_fatal("cannot parse $spec ($branch)") | |
91 | } | |
92 | ||
93 | File::Copy::move("tmp/$id/to-spool", "$spool_dir/$id") or die("move failed: $!"); | |
94 | ||
95 | cleanup(); | |
96 | ||
97 | exit(0); | |
98 | ||
99 | # vim: ts=2:sw=2:et |