8 open DEBUG, '>/dev/null' or die $!;
9 if (@ARGV && $ARGV[0] eq '-D') {
11 open DEBUG, '>&STDERR' or die $!;
14 die unless @ARGV>=1 && @ARGV<=2 && $ARGV[0] !~ m/^-/;
15 our ($dispatchdir,$authrune) = @ARGV;
17 $authrune //= join ':',
18 '@/keyrings/debian-keyring.gpg,a',
19 '@/keyrings/debian-maintainers.gpg,m@/dm.txt';
21 our $lre = $package_re;
22 our $qre = '["'."']?";
24 # $dispatchdir/distro=DISTRO should contain
25 # dgit-live a clone of dgit
27 # repos/ } by virtue of
28 # suites } dgit-repos-server's defaults relating to
29 # policy-hook } dispatch-dir
30 # plus files required by the authrune (by default, keyrings/ and dm.txt)
32 # diverts should be list of
34 # where <pat> is a package name pattern which may contain * or literals.
36 our ($distro,$pkg, $d);
37 our ($dgitlive,$repos,$suites,$diverts,$policyhook,$repo);
41 if (!open DIV, '<', $df) {
50 if (s/\s+(\S+)$//) { $divert=$1; }
51 s/[^-+._0-9a-zA-Z*]/\\$&/g;
53 printf DEBUG 'DISPATCH DIVERT ^%s$ %s'."\n",
54 $_, ($divert // '(undef)');
55 if ($pkg =~ m/^$_$/) { return $divert; }
57 DIV->error and die $!;
64 close STDOUT or die $!;
69 print @_, "\n" or die $!;
72 sub selectpackage ($$;$) {
74 ($distro,$pkg, $divertfn) = @_; # $distro,$pkg must have sane syntax
76 $d = "$dispatchdir/distro=$distro";
79 die $! unless $!==ENOENT;
80 die "unknown distro ($distro)\n";
83 $dgitlive= "$d/dgit-live";
86 $policyhook= "$d/policy-hook";
88 $authrune =~ s/\@/$d/g;
90 my $divert = checkdivert("$d/diverts");
91 if (defined $divert) {
93 die "diverted to $divert incompletely or too late!\n";
99 $repo = "$repos/$pkg.git";
101 print DEBUG "DISPATCH DISTRO $distro PKG $pkg\n";
109 $!==ENOENT or die $!;
115 local ($_) = $ENV{'SSH_ORIGINAL_COMMAND'};
117 if (m#^: dgit ($lre) git-check ($lre) ;#) {
118 selectpackage $1,$2, sub { prl "divert @_"; finish; };
122 m#^${qre}git-([-a-z]+) ${qre}/dgit/($lre)/repos/($lre)\.git${qre}$#
126 if ($cmd eq 'receive-pack') {
127 my $s = "$dgitlive/infra/dgit-repos-server";
128 exec $s, $distro, $d, $authrune, qw(--ssh);
130 } elsif ($cmd eq 'upload-pack') {
131 $repo='$repos/_empty' unless hasrepo;
132 exec qw(git upload-pack --strict --timeout=1000), $repo;
135 die "unsupported git operation $cmd ($_)";
138 die "unsupported operation ($_)";