#!/usr/bin/perl -w
-# $Id$
# read email with request from stdin and process it
+use Sys::Syslog;
+
+openlog("distfiles-rh", "pid", "user");
+
$spool_dir = "./spool";
$commits_list = "pld-cvs-commit\@lists.pld-linux.org";
sub report_fatal($)
{
my $msg = shift;
+
+ syslog("err","FATAL: $msg");
cleanup();
open(M, "| /usr/sbin/sendmail -t") or die("/usr/sbin/sendmail not found");
#open(M, "| cat") or die;
chomp $id;
$id = rand if (!defined $id or $id eq "");
+my $ref_pattern='[0-9a-zA-Z][0-9#a-zA-Z._\@/+ :,-]*';
while (<STDIN>) {
chomp;
- /^X-Spec: ([a-z0-9_.+-]+\.spec)/i and $spec = $1;
- /^X-Branch: ([a-z0-9_-]+)/i and $branch = $1;
+ /^X-Package: ([a-z0-9_.+-]+)/i and $spec = $1;
+ /^X-Branch: ($ref_pattern)/i and $branch = $1;
/^X-Login: ([a-z0-9_.]+)/i and $from = $1;
/^X-Flags: ([a-z0-9_ -]+)/i and $flags = $1;
}
-die "ill-formed request" if (!defined $from);
+if (!defined $from) {
+ syslog("err","FATAL: ill-formed request");
+ die "ill-formed request";
+}
+
+syslog("info","got request from $from for $spec at $branch ($flags)");
report_fatal("bad spec name") if (!defined $spec);
mkdir("tmp/$id") or die("cannot create: tmp/$id");
chdir("tmp/$id");
-$branch = "" if ($branch eq "HEAD");
-$branch = "-r \"$branch\"" if ($branch ne "");
-
-$specdir = File::Basename::basename($spec,('.spec'));
-if (system("cvs -d :pserver:cvs\@cvs.pld-linux.org:/cvsroot get $branch \"packages/$specdir/$spec\" >/dev/null 2>&1") != 0) {
+my $cvs_get = `~/distfiles/show_spec.sh $spec $branch 2>&1`;
+if ( $? ) {
chdir($oldcwd);
- report_fatal("cannot cvs get $spec at $branch")
+ my $at_branch = "";
+ $at_branch = " from branch $branch" if $branch;
+ my $code = $? >> 8;
+ report_fatal("cannot git fetch $spec$at_branch;\n$cvs_get\nexited with code $code");
}
chdir($oldcwd);
+syslog("info","spooling to tmp/$id/to-spool");
open(S, "> tmp/$id/to-spool");
print S "$from\@pld-linux.org\n";
print S "$spec\n";
print S "$flags\n";
close(S);
-if (system("perl ./specparser.pl \"tmp/$id/packages/$specdir/$spec\" >> tmp/$id/to-spool") != 0) {
+if (system("perl ./specparser.pl \"tmp/$id/$spec\" tmp/$id/sources >> tmp/$id/to-spool") != 0) {
report_fatal("cannot parse $spec ($branch)")
}
-File::Copy::move("tmp/$id/to-spool", "$spool_dir/$id") or die("move failed: $!");
+if (!File::Copy::move("tmp/$id/to-spool", "$spool_dir/$id")) {
+ syslog("err","FATAL: move failed: $!");
+ die("move failed: $!");
+}
cleanup();