chiark / gitweb /
WIP entirely new git approach with config parsers
[userv-utils.git] / git-daemon / git-service.in
1 #!/usr/bin/perl
2 #
3 # userv-git-daemon service script
4 #
5 # This was written by Tony Finch <dot@dotat.at> and subsequently
6 # heavily modified by Ian Jackson <ijackson@chiark.greenend.org.uk>
7 # http://creativecommons.org/publicdomain/zero/1.0/
8
9 use strict;
10 use warnings;
11
12 use Sys::Syslog;
13
14 our ($client,$service,$specpath,$spechost,@opts);
15
16 ${$::{$_}} = $ENV{"USERV_U_$_"}
17        for qw(service path host)
18
19 openlog "userv-$service", 'pid', 'daemon';
20 sub fail { syslog 'err', "$client @_"; exit }
21
22 @@READ_URLMAP@@
23
24 fail "No mapping for $uri ($ENV{USERV_USER})" unless defined $serve_user;
25
26 $1 = undef;
27 fail "Bad subdirectory $serve_dir" unless $serve_dir =~ m/$repo_regexp/o;
28 our $dir = $1;
29
30 $dir = "$ENV{HOME}/$dir" unless $dir =~ m|^/|;
31
32 $dir = "$dir/$repo" if defined $repo;
33 $path = $check_export ? "$dir/git-daemon-export-ok" : $dir;
34 fail "$! $path" unless -e $path;
35 syslog 'notice', "$client $dir";
36
37 @opts = qw( --strict )
38    if @opts == 0 and $service eq 'git-upload-pack';
39
40 my @cmd = ($service =~ m|^(git)-(.*)$|, @opts, $dir);
41 no warnings; # suppress errors to stderr
42 exec @cmd or fail "exec $service: $!";
43
44 # end