git-daemon: include an example inetd.conf line.
[userv-utils] / git-daemon / git-service
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
9ad7f5ed
TF
14${$::{$_}} = $ENV{"USERV_U_$_"}
15 for grep s|^USERV_U_([a-z_]+)$|$1|, keys %ENV;
18c4999f 16
9ad7f5ed 17our ($client,$service,$path,$host);
18c4999f 18
cb5c438e 19openlog "userv-$service", 'pid', 'daemon';
3b32ef57 20sub fail { syslog 'err', "$client @_"; exit }
18c4999f 21
9ad7f5ed
TF
22our ($check_repo,$check_export,$dir,$repo) = (1,0);
23our $uri = $_ = "git://$host/$path";
3b32ef57 24for my $cf (@ARGV) { do $cf }
18c4999f 25
18c4999f
TF
26my $home = (getpwuid $<)[7];
27$dir = "$home/$dir" if $dir =~ m|^[^/]|
28 or $dir =~ s|^~/||;
9ad7f5ed
TF
29fail "Bad filename $repo" if $check_repo
30 and $repo !~ m|^\w[\w.=+-]*\.git$|;
31$dir = "$dir/$repo" if defined $repo;
32$path = $check_export ? "$dir/git-daemon-export-ok" : $dir;
33fail "$! $path" unless -e $path;
34syslog 'notice', "$client $dir";
18c4999f 35
3b32ef57 36my @cmd = ($service, '--strict', '--timeout=30', $dir);
18c4999f 37no warnings; # suppress errors to stderr
9ad7f5ed 38exec @cmd or fail "exec $service: $!";
18c4999f
TF
39
40# end