chiark / gitweb /
Test suite: import-nonnative: Test tarbombs
[dgit.git] / infra / dgit-ssh-dispatch
index f29515f53e073c8b19e7345f950a278dad58e896..c5861d2d8b4223ca764e24f78df6223714ef7b47 100755 (executable)
@@ -1,9 +1,28 @@
 #!/usr/bin/perl -w
+# wrapper to dispatch git ssh service requests
+#
+# Copyright (C) 2015-2016  Ian Jackson
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 use strict;
-use POSIX;
 
+use Debian::Dgit::Infra; # must precede Debian::Dgit; - can change @INC!
 use Debian::Dgit;
+setup_sigwarn();
+
+use POSIX;
 
 open DEBUG, '>/dev/null' or die $!;
 if (@ARGV && $ARGV[0] eq '-D') {
@@ -22,7 +41,7 @@ our $lre = $package_re;
 our $qre = '["'."']?";
 
 # $dispatchdir/distro=DISTRO should contain
-#    dgit-live   a clone of dgit
+#    dgit-live          a clone of dgit (only if not using installed vsns)
 #    diverts
 #    repos/             }  by virtue of
 #    suites             }    dgit-repos-server's defaults relating to
@@ -32,6 +51,7 @@ our $qre = '["'."']?";
 # diverts should be list of
 #  <pat> [<divert-to>]
 # where <pat> is a package name pattern which may contain * or literals.
+# <divert-to> is for `git config dgit-distro.DISTRO.diverts.<divert-to>'
 
 our ($distro,$pkg, $d);
 our ($dgitlive,$repos,$suites,$diverts,$policyhook,$repo);
@@ -111,29 +131,48 @@ sub hasrepo () {
     }
 }
 
+sub serve_up ($) {
+    my ($repo) = @_;
+    exec qw(git upload-pack --strict --timeout=1000), $repo;
+    die "exec git: $!";
+}
+
 sub dispatch () {
-    local ($_) = $ENV{'SSH_ORIGINAL_COMMAND'};
+    local ($_) = $ENV{'SSH_ORIGINAL_COMMAND'} // '';
 
     if (m#^: dgit ($lre) git-check ($lre) ;#) {
        selectpackage $1,$2, sub { prl "divert @_"; finish; };
        prl hasrepo;
        finish;
     } elsif (
-        m#^${qre}git-([-a-z]+) ${qre}/dgit/($lre)/repos/($lre)\.git${qre}$#
-    ) {
+       m#^${qre}git-([-a-z]+) ${qre}/dgit/($lre)/repos/($lre)\.git${qre}$#
+       ) {
        my $cmd=$1;
        selectpackage $2,$3;
        if ($cmd eq 'receive-pack') {
+           $ENV{'PERLLIB'} //= '';
+           $ENV{'PERLLIB'} =~ s#^(?=.)#:#;
+           $ENV{'PERLLIB'} =~ s#^# $ENV{DGIT_TEST_INTREE} // $dgitlive #e;
            my $s = "$dgitlive/infra/dgit-repos-server";
+           $s = "dgit-repos-server" if !stat_exists $s;
            exec $s, $distro, $d, $authrune, qw(--ssh);
            die "exec $s: $!";
        } elsif ($cmd eq 'upload-pack') {
            $repo='$repos/_empty' unless hasrepo;
-           exec qw(git upload-pack --strict --timeout=1000), $repo;
-           die "exec git: $!";
+           serve_up $repo;
        } else {
            die "unsupported git operation $cmd ($_)";
        }
+    } elsif (
+ m#^${qre}git-upload-pack ${qre}/dgit/($lre)/(?:repos/)?_dgit-repos-server\.git${qre}$#
+       ) {
+       my $distro= $1;
+       # if running installed packages, source code should come
+       # some other way
+       serve_up("$dispatchdir/distro=$1/dgit-live/.git");
+    } elsif (m#^${qre}git-upload-pack\s#) {
+       die "unknown repo to serve ($_).  use dgit, or for server source ".
+           "git clone here:/dgit/DISTRO/repos/_dgit-repos-server.git";
     } else {
        die "unsupported operation ($_)";
     }