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