log repository location
[userv-utils] / git-daemon / git-daemon-service.pl
CommitLineData
18c4999f
TF
1#!/usr/bin/perl
2#
3# userv-git-daemon service script
4#
5# This was written by Tony Finch <dot@dotat.at>
6# You may do anything with it, at your own risk.
7# http://creativecommons.org/publicdomain/zero/1.0/
8
9use strict;
10use warnings;
11
12use Sys::Syslog;
13
3b32ef57
TF
14our $check_repo = 1;
15our $check_export = 0;
16our ($service,$client,$dir,$repo);
18c4999f 17
3b32ef57 18${$main::{$_}} = $ENV{"USERV_U_$_"}
18c4999f
TF
19 for grep s/^USERV_U_//, keys %ENV;
20
cb5c438e 21openlog "userv-$service", 'pid', 'daemon';
3b32ef57 22sub fail { syslog 'err', "$client @_"; exit }
18c4999f 23
18c4999f 24$_ = our $uri;
3b32ef57 25for my $cf (@ARGV) { do $cf }
18c4999f
TF
26
27fail "no repository configured for $uri" unless defined $repo;
28fail "no directory configured for $uri" unless defined $dir;
29
30my $home = (getpwuid $<)[7];
31$dir = "$home/$dir" if $dir =~ m|^[^/]|
32 or $dir =~ s|^~/||;
33$dir = "$dir/$repo";
34
35fail "bad repository in $uri"
36 if $check_repo and $repo !~ /^[0-9A-Za-z._-]+[.]git$/;
37fail "repository not exported for $uri"
38 if $check_export and not -e "$dir/git-daemon-export-ok";
cb5c438e 39syslog 'info', "$client $dir";
18c4999f 40
3b32ef57 41my @cmd = ($service, '--strict', '--timeout=30', $dir);
18c4999f
TF
42no warnings; # suppress errors to stderr
43exec @cmd or fail "exec @cmd: $!";
44
45# end