X-Git-Url: https://git.distorted.org.uk/~mdw/userv-utils/blobdiff_plain/08e30b5e72511f4d6b026b40ab3125ae05c81868..18c4999f61d703d687b3c96e419ec9f4d81541fe:/git-daemon/git-daemon-service.pl diff --git a/git-daemon/git-daemon-service.pl b/git-daemon/git-daemon-service.pl new file mode 100755 index 0000000..ec4b7e1 --- /dev/null +++ b/git-daemon/git-daemon-service.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl +# +# userv-git-daemon service script +# +# This was written by Tony Finch +# You may do anything with it, at your own risk. +# http://creativecommons.org/publicdomain/zero/1.0/ + +use strict; +use warnings; + +use Sys::Syslog; + +my $service = $ENV{"USERV_SERVICE"}; +$service =~ s|^git-||; + +${$cf::{$_}} = $ENV{"USERV_U_$_"} + for grep s/^USERV_U_//, keys %ENV; + +openlog 'userv-git-daemon/$service', 'pid', 'daemon'; + +sub cf::fail { + syslog 'err', "$cf::client @_"; + exit; +} + +package cf; + +our $check_repo = 1; +our $check_export = 0; +our ($dir,$repo,$client); +$_ = our $uri; +for my $cf (@ARGV) { + do $cf; +} + +fail "no repository configured for $uri" unless defined $repo; +fail "no directory configured for $uri" unless defined $dir; + +my $home = (getpwuid $<)[7]; +$dir = "$home/$dir" if $dir =~ m|^[^/]| + or $dir =~ s|^~/||; +$dir = "$dir/$repo"; + +fail "bad repository in $uri" + if $check_repo and $repo !~ /^[0-9A-Za-z._-]+[.]git$/; +fail "repository not exported for $uri" + if $check_export and not -e "$dir/git-daemon-export-ok"; + +my @cmd = ('git', $service, '--strict', '--timeout=30', $dir); +no warnings; # suppress errors to stderr +exec @cmd or fail "exec @cmd: $!"; + +# end