]>
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(); |
472da1da JR |
32 | |
33 | my $email_head = | |
9300ac96 | 34 | "Subject: DISTFILES: ERROR fetching sources for $spec ($branch) |
958ed10f | 35 | X-distfiles-program: request-handler.pl"; |
472da1da JR |
36 | my $email_body = |
37 | "$msg | |
a04817ac MM |
38 | |
39 | -- | |
40 | Virtually Yours: distfiles. | |
472da1da JR |
41 | "; |
42 | ||
43 | open(M, "| /usr/sbin/sendmail -t") or die("/usr/sbin/sendmail not found"); | |
44 | #open(M, "| cat") or die; | |
45 | print M | |
9300ac96 JR |
46 | "From: $from <$from\@pld-linux.org> |
47 | To: $commits_list | |
472da1da JR |
48 | $email_head |
49 | Message-ID: <$$." . time . "$id\@distfiles.pld-linux.org> | |
50 | ||
9300ac96 JR |
51 | Requester: $from |
52 | ||
472da1da JR |
53 | $email_body"; |
54 | close(M) or die("problem while sending email"); | |
55 | ||
56 | open(M, "| /usr/sbin/sendmail -t") or die("/usr/sbin/sendmail not found"); | |
57 | #open(M, "| cat") or die; | |
58 | print M | |
9300ac96 JR |
59 | "From: <distfiles\@distfiles.pld-linux.org> |
60 | To: <$from\@pld-linux.org> | |
472da1da JR |
61 | $email_head |
62 | Message-ID: <$$." . time . "$id\@distfiles.pld-linux.org> | |
63 | ||
64 | $email_body"; | |
b5160615 | 65 | close(M) or die("problem while sending email"); |
a04817ac MM |
66 | exit 0; |
67 | } | |
68 | # --------------------------------------------------------------- | |
69 | ||
052c958f MM |
70 | $id = `uuidgen`; |
71 | chomp $id; | |
72 | $id = rand if (!defined $id or $id eq ""); | |
73 | ||
0e296d4e | 74 | my $ref_pattern='[0-9a-zA-Z][0-9#a-zA-Z._\@/+ :,-]*'; |
052c958f | 75 | while (<STDIN>) { |
47f8fda7 | 76 | chomp; |
ad64e6a8 | 77 | /^X-Package: ([a-z0-9_.+-]+)/i and $spec = $1; |
0e296d4e | 78 | /^X-Branch: ($ref_pattern)/i and $branch = $1; |
576dff03 ER |
79 | /^X-Login: ([a-z0-9_.]+)/i and $from = $1; |
80 | /^X-Flags: ([a-z0-9_ -]+)/i and $flags = $1; | |
052c958f MM |
81 | } |
82 | ||
631fa1b7 MM |
83 | if (!defined $from) { |
84 | syslog("err","FATAL: ill-formed request"); | |
85 | die "ill-formed request"; | |
86 | } | |
87 | ||
88 | syslog("info","got request from $from for $spec at $branch ($flags)"); | |
052c958f MM |
89 | |
90 | report_fatal("bad spec name") if (!defined $spec); | |
91 | ||
d22382ac | 92 | $oldcwd = Cwd::getcwd(); |
9654851f | 93 | |
b5160615 | 94 | mkdir("tmp/$id") or die("cannot create: tmp/$id"); |
052c958f MM |
95 | chdir("tmp/$id"); |
96 | ||
a106d34c | 97 | my $cvs_get = `~/distfiles/show_spec.sh $spec $branch 2>&1`; |
1f167206 | 98 | if ( $? ) { |
d22382ac | 99 | chdir($oldcwd); |
1f167206 | 100 | my $at_branch = ""; |
101 | $at_branch = " from branch $branch" if $branch; | |
102 | my $code = $? >> 8; | |
ad64e6a8 | 103 | report_fatal("cannot git fetch $spec$at_branch;\n$cvs_get\nexited with code $code"); |
052c958f MM |
104 | } |
105 | ||
d22382ac | 106 | chdir($oldcwd); |
052c958f | 107 | |
631fa1b7 | 108 | syslog("info","spooling to tmp/$id/to-spool"); |
052c958f MM |
109 | open(S, "> tmp/$id/to-spool"); |
110 | print S "$from\@pld-linux.org\n"; | |
cba859d3 | 111 | print S "$spec\n"; |
47f8fda7 | 112 | print S "$flags\n"; |
052c958f MM |
113 | close(S); |
114 | ||
8b8c50a0 | 115 | if (system("perl ./specparser.pl \"tmp/$id/$spec\" tmp/$id/sources >> tmp/$id/to-spool") != 0) { |
052c958f MM |
116 | report_fatal("cannot parse $spec ($branch)") |
117 | } | |
118 | ||
631fa1b7 MM |
119 | if (!File::Copy::move("tmp/$id/to-spool", "$spool_dir/$id")) { |
120 | syslog("err","FATAL: move failed: $!"); | |
121 | die("move failed: $!"); | |
122 | } | |
052c958f MM |
123 | |
124 | cleanup(); | |
125 | ||
126 | exit(0); | |
127 | ||
319fb6c1 | 128 | # vim: ts=2:sw=2:et |