Commit | Line | Data |
---|---|---|
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 | ||
9 | use strict; | |
10 | use warnings; | |
11 | ||
12 | use Sys::Syslog; | |
13 | ||
3b32ef57 TF |
14 | our $check_repo = 1; |
15 | our $check_export = 0; | |
16 | our ($service,$client,$dir,$repo); | |
18c4999f | 17 | |
3b32ef57 | 18 | ${$main::{$_}} = $ENV{"USERV_U_$_"} |
18c4999f TF |
19 | for grep s/^USERV_U_//, keys %ENV; |
20 | ||
3b32ef57 TF |
21 | openlog 'userv-$service', 'pid', 'daemon'; |
22 | sub fail { syslog 'err', "$client @_"; exit } | |
18c4999f | 23 | |
18c4999f | 24 | $_ = our $uri; |
3b32ef57 | 25 | for my $cf (@ARGV) { do $cf } |
18c4999f TF |
26 | |
27 | fail "no repository configured for $uri" unless defined $repo; | |
28 | fail "no directory configured for $uri" unless defined $dir; | |
29 | ||
30 | my $home = (getpwuid $<)[7]; | |
31 | $dir = "$home/$dir" if $dir =~ m|^[^/]| | |
32 | or $dir =~ s|^~/||; | |
33 | $dir = "$dir/$repo"; | |
34 | ||
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 | ||
3b32ef57 | 40 | my @cmd = ($service, '--strict', '--timeout=30', $dir); |
18c4999f TF |
41 | no warnings; # suppress errors to stderr |
42 | exec @cmd or fail "exec @cmd: $!"; | |
43 | ||
44 | # end |