summaryrefslogtreecommitdiff
path: root/git-daemon/git-service.in
blob: 2b8aff34e4705f441840a10490285bd264c1c5d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
#
# userv-git-daemon service script
#
# 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;
use warnings;

use POSIX;
use Sys::Syslog;

our ($client,$service,$specpath,$spechost,@opts);

${$::{$_}} = $ENV{"USERV_U_$_"}
       for qw(service specpath spechost client);

openlog "userv-$service:$ENV{USER}", 'pid', 'daemon';
sub fail { syslog 'err', "$client @_"; exit }

@@READ_URLMAP@@

fail "No user $ENV{USER} mapping for $uri" unless defined $serve_user;

$serve_dir = "$ENV{HOME}/$serve_dir" unless $serve_dir =~ m|^/|;

if (length $serve_repo) {
    my $inspect= $serve_repo;
    $inspect =~ s,^/,,;
    fail "Bad subdirectory $serve_repo" unless $inspect =~ m/$repo_regexp/o;
    fail "bad config - repo-regexp does not capture" unless defined $1;
    $serve_repo= "/$1";
}

my $dir = $serve_dir.$serve_repo;

my $path = $check_export ? "$dir/git-daemon-export-ok" : $dir;
fail "$! $path" unless -e $path;

syslog 'notice', "$client $uri $dir";

@opts = qw( --strict )
   if @opts == 0 and $service eq 'git-upload-pack';

my @cmd = ($service =~ m|^(git)-(.*)$|, @opts, $dir);
no warnings; # suppress errors to stderr
exec @cmd or fail "exec $service: $!";

# end