chiark / gitweb /
dgit-repos-server etc.: Rework argument & distros-dir passing (no overall functional...
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 23 Apr 2015 14:03:29 +0000 (15:03 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 31 May 2015 10:54:06 +0000 (11:54 +0100)
infra/dgit-repos-server
infra/dgit-ssh-dispatch
tests/drs-git-ext

index d3d711f178ab99fda55dbe849fd77114f98b6e01..93f6481e35a1a2a605adcb6f7a82bd615bd1a7e8 100755 (executable)
@@ -2,10 +2,13 @@
 # dgit-repos-server
 #
 # usages:
 # dgit-repos-server
 #
 # usages:
-#  .../dgit-repos-server DISTRO SUITES KEYRING-AUTH-SPEC \
-#      DGIT-REPOS-DIR POLICY-HOOK-SCRIPT --ssh
-#  .../dgit-repos-server DISTRO SUITES KEYRING-AUTH-SPEC \
-#      DGIT-REPOS-DIR POLICY-HOOK-SCRIPT --cron
+#   dgit-repos-server DISTRO DISTRO-DIR AUTH-SPEC [<settings>] --ssh
+#   dgit-repos-server DISTRO DISTRO-DIR AUTH-SPEC [<settings>] --cron
+# settings
+#   --repos=GIT-REPOS-DIR      default DISTRO-DIR/repos/
+#   --suites=SUITES-FILE       default DISTRO-DIR/suites
+#   --policy-hook=POLICY-HOOK  default DISTRO-DIR/policy-hook
+# (DISTRO-DIR is not used other than as default)
 # internal usage:
 #  .../dgit-repos-server --pre-receive-hook PACKAGE
 #
 # internal usage:
 #  .../dgit-repos-server --pre-receive-hook PACKAGE
 #
@@ -16,7 +19,7 @@
 # SUITES is the name of a file which lists the permissible suites
 # one per line (#-comments and blank lines ignored)
 #
 # SUITES is the name of a file which lists the permissible suites
 # one per line (#-comments and blank lines ignored)
 #
-# KEYRING-AUTH-SPEC is a :-separated list of
+# AUTH-SPEC is a :-separated list of
 #   KEYRING.GPG,AUTH-SPEC
 # where AUTH-SPEC is one of
 #   a
 #   KEYRING.GPG,AUTH-SPEC
 # where AUTH-SPEC is one of
 #   a
@@ -783,6 +786,17 @@ sub argval () {
     return $v;
 }
 
     return $v;
 }
 
+our %indistrodir = (
+    # keys are used for DGIT_DRS_XXX too
+    'repos' => \$dgitrepos,
+    'suites' => \$suitesfile,
+    'policy-hook' => \$policyhook,
+    );
+
+our @hookenvs = qw(distro suitesfile policyhook keyrings dgitrepos);
+
+# workrepo and destrepo handled ad-hoc
+
 sub parseargsdispatch () {
     die unless @ARGV;
 
 sub parseargsdispatch () {
     die unless @ARGV;
 
@@ -799,13 +813,9 @@ sub parseargsdispatch () {
        shift @ARGV;
        @ARGV == 1 or die;
        $package = shift @ARGV;
        shift @ARGV;
        @ARGV == 1 or die;
        $package = shift @ARGV;
-       defined($distro = $ENV{'DGIT_DRS_DISTRO'}) or die;
-       defined($dgitrepos = $ENV{'DGIT_DRS_REPOS'}) or die;
-       defined($suitesfile = $ENV{'DGIT_DRS_SUITES'}) or die;
+       ${ $main::{$_} } = $ENV{"DGIT_DRS_\U$_"} foreach @hookenvs;
        defined($workrepo = $ENV{'DGIT_DRS_WORK'}) or die;
        defined($destrepo = $ENV{'DGIT_DRS_DEST'}) or die;
        defined($workrepo = $ENV{'DGIT_DRS_WORK'}) or die;
        defined($destrepo = $ENV{'DGIT_DRS_DEST'}) or die;
-       defined($keyrings = $ENV{'DGIT_DRS_KEYRINGS'}) or die $!;
-       defined($policyhook = $ENV{'DGIT_DRS_POLICYHOOK'}) or die $!;
        open STDOUT, ">&STDERR" or die $!;
        eval {
            stunthook();
        open STDOUT, ">&STDERR" or die $!;
        eval {
            stunthook();
@@ -817,11 +827,20 @@ sub parseargsdispatch () {
        exit 0;
     }
 
        exit 0;
     }
 
-    $ENV{'DGIT_DRS_DISTRO'} = $distro = argval();
-    $ENV{'DGIT_DRS_SUITES'} = $suitesfile = argval();
-    $ENV{'DGIT_DRS_KEYRINGS'} = $keyrings = argval();
-    $ENV{'DGIT_DRS_REPOS'} = $dgitrepos = argval();
-    $ENV{'DGIT_DRS_POLICYHOOK'} = $policyhook = argval();
+    $distro = $ENV{'DGIT_DRS_DISTRO'}     = argval();
+    my $distrodir                         = argval();
+    $keyrings = $ENV{'DGIT_DRS_KEYRINGS'} = argval();
+
+    foreach my $dk (keys %indistrodir) {
+       ${ $indistrodir{$dk} } = "$distrodir/$dk";
+    }
+
+    while (@ARGV && $ARGV[0] =~ m/^--([-0-9a-z]+)=/ && $indistrodir{$1}) {
+       ${ $indistrodir{$1} } = $'; #';
+       shift @ARGV;
+    }
+
+    $ENV{"DGIT_DRS_\U$_"} = ${ $main::{$_} } foreach @hookenvs;
 
     die unless @ARGV==1 && $ARGV[0] eq '--ssh';
 
 
     die unless @ARGV==1 && $ARGV[0] eq '--ssh';
 
index 4769d895830f5aa154e49fc0cc94f069a9e68bb4..f29515f53e073c8b19e7345f950a278dad58e896 100755 (executable)
@@ -21,19 +21,19 @@ $authrune //= join ':',
 our $lre = $package_re;
 our $qre = '["'."']?";
 
 our $lre = $package_re;
 our $qre = '["'."']?";
 
-# $dispatchdir should contain
+# $dispatchdir/distro=DISTRO should contain
 #    dgit-live   a clone of dgit
 #    dgit-live   a clone of dgit
-#    repos/
-#    suites
 #    diverts
 #    diverts
-#    policy-hook
+#    repos/             }  by virtue of
+#    suites             }    dgit-repos-server's defaults relating to
+#    policy-hook        }    dispatch-dir
 # plus files required by the authrune (by default, keyrings/ and dm.txt)
 #
 # diverts should be list of
 #  <pat> [<divert-to>]
 # where <pat> is a package name pattern which may contain * or literals.
 
 # plus files required by the authrune (by default, keyrings/ and dm.txt)
 #
 # diverts should be list of
 #  <pat> [<divert-to>]
 # where <pat> is a package name pattern which may contain * or literals.
 
-our ($distro,$pkg);
+our ($distro,$pkg, $d);
 our ($dgitlive,$repos,$suites,$diverts,$policyhook,$repo);
 
 sub checkdivert ($) {
 our ($dgitlive,$repos,$suites,$diverts,$policyhook,$repo);
 
 sub checkdivert ($) {
@@ -73,7 +73,7 @@ sub selectpackage ($$;$) {
     my $divertfn;
     ($distro,$pkg, $divertfn) = @_; # $distro,$pkg must have sane syntax
 
     my $divertfn;
     ($distro,$pkg, $divertfn) = @_; # $distro,$pkg must have sane syntax
 
-    my $d = "$dispatchdir/distro=$distro";
+    $d = "$dispatchdir/distro=$distro";
 
     if (!stat $d) {
        die $! unless $!==ENOENT;
 
     if (!stat $d) {
        die $! unless $!==ENOENT;
@@ -125,8 +125,7 @@ sub dispatch () {
        selectpackage $2,$3;
        if ($cmd eq 'receive-pack') {
            my $s = "$dgitlive/infra/dgit-repos-server";
        selectpackage $2,$3;
        if ($cmd eq 'receive-pack') {
            my $s = "$dgitlive/infra/dgit-repos-server";
-           exec $s, $distro, $suites, $authrune, $repos,
-                   $policyhook, qw(--ssh);
+           exec $s, $distro, $d, $authrune, qw(--ssh);
            die "exec $s: $!";
        } elsif ($cmd eq 'upload-pack') {
            $repo='$repos/_empty' unless hasrepo;
            die "exec $s: $!";
        } elsif ($cmd eq 'upload-pack') {
            $repo='$repos/_empty' unless hasrepo;
index 8116a87438c3cae0bb0c85aa47123e1d65a22e11..13646d366df1181aa0ec5260d59590e729114565 100755 (executable)
@@ -6,10 +6,9 @@ export DGIT_DRS_DEBUG=1
 echo >&2 '(((((((((((((((((((((((((((((((((((((((('
 set -x
 export SSH_ORIGINAL_COMMAND="$*"
 echo >&2 '(((((((((((((((((((((((((((((((((((((((('
 set -x
 export SSH_ORIGINAL_COMMAND="$*"
-${DGIT_REPOS_SERVER_TEST-dgit-repos-server} test-dummy \
-       $tmp/suites \
+${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
+       test-dummy $tmp/distro=test-dummy \
        $tmp/dd.gpg,a:$tmp/dm.gpg,m$tmp/dm.txt \
        $tmp/dd.gpg,a:$tmp/dm.gpg,m$tmp/dm.txt \
-       $tmp/git \
-       /bin/true \
+       --repos=$tmp/git --policy-hook=/bin/true --suites=$tmp/suites \
        --ssh
 : '))))))))))))))))))))))))))))))))))))))))'
        --ssh
 : '))))))))))))))))))))))))))))))))))))))))'