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
28 # plus files required by the authrune (by default, keyrings/ and dm.txt)
30 # diverts should be list of
32 # where <pat> is a package name pattern which may contain * or literals.
35 our ($dgitlive,$repos,$suites,$diverts,$policyhook,$repo);
39 if (!open DIV, '<', $df) {
48 if (s/\s+(\S+)$//) { $divert=$1; }
49 s/[^-+._0-9a-zA-Z*]/\\$&/g;
51 printf DEBUG 'DISPATCH DIVERT ^%s$ %s'."\n",
52 $_, ($divert // '(undef)');
53 if ($pkg =~ m/^$_$/) { return $divert; }
55 DIV->error and die $!;
62 close STDOUT or die $!;
67 print @_, "\n" or die $!;
70 sub selectpackage ($$;$) {
72 ($distro,$pkg, $divertfn) = @_; # $distro,$pkg must have sane syntax
74 my $d = "$dispatchdir/distro=$distro";
77 die $! unless $!==ENOENT;
78 die "unknown distro ($distro)\n";
81 $dgitlive= "$d/dgit-live";
84 $policyhook= "$d/policy-hook";
86 $authrune =~ s/\@/$d/g;
88 my $divert = checkdivert("$d/diverts");
89 if (defined $divert) {
91 die "diverted to $divert incompletely or too late!\n";
97 $repo = "$repos/$pkg.git";
99 print DEBUG "DISPATCH DISTRO $distro PKG $pkg\n";
107 $!==ENOENT or die $!;
113 local ($_) = $ENV{'SSH_ORIGINAL_COMMAND'};
115 if (m#^: dgit ($lre) git-check ($lre) ;#) {
116 selectpackage $1,$2, sub { prl "divert @_"; finish; };
120 m#^${qre}git-([-a-z]+) ${qre}/dgit/($lre)/repos/($lre)\.git${qre}$#
124 if ($cmd eq 'receive-pack') {
125 my $s = "$dgitlive/infra/dgit-repos-server";
126 exec $s, $distro, $suites, $authrune, $repos,
127 $policyhook, qw(--ssh);
129 } elsif ($cmd eq 'upload-pack') {
130 $repo='$repos/_empty' unless hasrepo;
131 exec qw(git upload-pack --strict --timeout=1000), $repo;
134 die "unsupported git operation $cmd ($_)";
137 die "unsupported operation ($_)";