3 # userv-git-daemon service script
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/
15 our $check_export = 0;
16 our ($service,$client,$dir,$repo);
18 ${$main::{$_}} = $ENV{"USERV_U_$_"}
19 for grep s/^USERV_U_//, keys %ENV;
21 openlog "userv-$service", 'pid', 'daemon';
22 sub fail { syslog 'err', "$client @_"; exit }
25 for my $cf (@ARGV) { do $cf }
27 fail "no repository configured for $uri" unless defined $repo;
28 fail "no directory configured for $uri" unless defined $dir;
30 my $home = (getpwuid $<)[7];
31 $dir = "$home/$dir" if $dir =~ m|^[^/]|
35 fail "bad repository in $uri"
36 if $check_repo and $repo !~ /^[0-9A-Za-z._-]+[.]git$/;
37 fail "repository not exported for $uri"
38 if $check_export and not -e "$dir/git-daemon-export-ok";
39 syslog 'info', "$client $dir";
41 my @cmd = ($service, '--strict', '--timeout=30', $dir);
42 no warnings; # suppress errors to stderr
43 exec @cmd or fail "exec @cmd: $!";