6 open DEBUG, '>/dev/null' or die $!;
7 if (@ARGV && $ARGV[0] eq '-D') {
9 open DEBUG, '>&STDERR' or die $!;
12 die unless @ARGV>=1 && @ARGV<=2 && $ARGV[0] !~ m/^-/;
13 our ($dispatchdir,$authrune) = @ARGV;
15 $authrune //= join ':',
16 '@/keyrings/debian-keyring.gpg,a',
17 '@/keyrings/debian-maintainers.gpg,m@/dm.txt';
19 our $lre = '[0-9a-z][-+.0-9a-z]*';
20 our $qre = '["'."']?";
22 # $dispatchdir should contain
23 # dgit-live a clone of dgit
27 # plus files required by the authrune (by default, keyrings/ and dm.txt)
29 # diverts should be list of
31 # where <pat> is a package name pattern which may contain * or literals.
34 our ($dgitlive,$repos,$suites,$diverts,$repo);
38 if (!open DIV, '<', $df) {
47 if (s/\s+(\S+)$//) { $divert=$1; }
48 s/[^-+._0-9a-zA-Z*]/\\$&/g;
50 printf DEBUG 'DISPATCH DIVERT ^%s$ %s'."\n",
51 $_, ($divert // '(undef)');
52 if ($pkg =~ m/^$_$/) { return $divert; }
54 DIV->error and die $!;
61 close STDOUT or die $!;
66 print @_, "\n" or die $!;
69 sub selectpackage ($$;$) {
71 ($distro,$pkg, $divertfn) = @_; # $distro,$pkg must have sane syntax
73 my $d = "$dispatchdir/distro=$distro";
76 die $! unless $!==ENOENT;
77 die "unknown distro ($distro)\n";
80 $dgitlive= "$d/dgit-live";
84 $authrune =~ s/\@/$d/g;
86 my $divert = checkdivert("$d/diverts");
87 if (defined $divert) {
89 die "diverted to $divert incompletely or too late!\n";
95 $repo = "$repos/$pkg.git";
97 print DEBUG "DISPATCH DISTRO $distro PKG $pkg\n";
105 $!==ENOENT or die $!;
111 local ($_) = $ENV{'SSH_ORIGINAL_COMMAND'};
113 if (m#^: dgit ($lre) git-check ($lre) ;#) {
114 selectpackage $1,$2, sub { prl "divert @_"; finish; };
118 m#^${qre}git-([-a-z]+) ${qre}/dgit/($lre)/repos/($lre)\.git${qre}$#
122 if ($cmd eq 'receive-pack') {
123 my $s = "$dgitlive/infra/dgit-repos-server";
124 exec $s, $suites, $authrune, $repos, qw(--ssh);
126 } elsif ($cmd eq 'upload-pack') {
127 $repo='$repos/_empty' unless hasrepo;
128 exec qw(git upload-pack --strict --timeout=1000), $repo;
131 die "unsupported git operation $cmd ($_)";
134 die "unsupported operation ($_)";