chiark / gitweb /
WIP entirely new git approach with config parsers
[userv-utils.git] / git-daemon / git-service.in
similarity index 53%
rename from git-daemon/git-service
rename to git-daemon/git-service.in
index aeb4e0e10a397e4c5e2284ba5a5faa237f747898..43ff340a70f58335f17ab65c9e48dd8c7d480d49 100755 (executable)
@@ -2,8 +2,8 @@
 #
 # userv-git-daemon service script
 #
-# This was written by Tony Finch <dot@dotat.at>
-# You may do anything with it, at your own risk.
+# This was written by Tony Finch <dot@dotat.at> and subsequently
+# heavily modified by Ian Jackson <ijackson@chiark.greenend.org.uk>
 # http://creativecommons.org/publicdomain/zero/1.0/
 
 use strict;
@@ -11,29 +11,30 @@ use warnings;
 
 use Sys::Syslog;
 
-${$::{$_}} = $ENV{"USERV_U_$_"}
-       for grep s|^USERV_U_([a-z_]+)$|$1|, keys %ENV;
+our ($client,$service,$specpath,$spechost,@opts);
 
-our ($client,$service,$path,$host,@opts);
+${$::{$_}} = $ENV{"USERV_U_$_"}
+       for qw(service path host)
 
 openlog "userv-$service", 'pid', 'daemon';
 sub fail { syslog 'err', "$client @_"; exit }
 
-our ($check_repo,$check_export,$dir,$repo) = (1,0);
-our $uri = $_ = "git://$host/$path";
-for my $cf (@ARGV) { do $cf }
+@@READ_URLMAP@@
+
+fail "No mapping for $uri ($ENV{USERV_USER})" unless defined $serve_user;
+
+$1 = undef;
+fail "Bad subdirectory $serve_dir" unless $serve_dir =~ m/$repo_regexp/o;
+our $dir = $1;
+
+$dir = "$ENV{HOME}/$dir" unless $dir =~ m|^/|;
 
-my $home = (getpwuid $<)[7];
-$dir = "$home/$dir" if $dir =~ m|^[^/]|
-                    or $dir =~ s|^~/||;
-fail "Bad filename $repo" if $check_repo
-               and $repo !~ m|^\w[\w.=+-]*\.git$|;
 $dir = "$dir/$repo" if defined $repo;
 $path = $check_export ? "$dir/git-daemon-export-ok" : $dir;
 fail "$! $path" unless -e $path;
 syslog 'notice', "$client $dir";
 
-@opts = qw( --strict --timeout-30 )
+@opts = qw( --strict )
    if @opts == 0 and $service eq 'git-upload-pack';
 
 my @cmd = ($service =~ m|^(git)-(.*)$|, @opts, $dir);