Commit | Line | Data |
---|---|---|
18c4999f TF |
1 | #!/usr/bin/perl |
2 | # | |
3 | # userv-git-daemon service script | |
4 | # | |
d36c5f7b IJ |
5 | # This was written by Tony Finch <dot@dotat.at> and subsequently |
6 | # heavily modified by Ian Jackson <ijackson@chiark.greenend.org.uk> | |
18c4999f TF |
7 | # http://creativecommons.org/publicdomain/zero/1.0/ |
8 | ||
9 | use strict; | |
10 | use warnings; | |
11 | ||
12 | use Sys::Syslog; | |
13 | ||
d36c5f7b | 14 | our ($client,$service,$specpath,$spechost,@opts); |
18c4999f | 15 | |
d36c5f7b IJ |
16 | ${$::{$_}} = $ENV{"USERV_U_$_"} |
17 | for qw(service path host) | |
18c4999f | 18 | |
cb5c438e | 19 | openlog "userv-$service", 'pid', 'daemon'; |
3b32ef57 | 20 | sub fail { syslog 'err', "$client @_"; exit } |
18c4999f | 21 | |
d36c5f7b IJ |
22 | @@READ_URLMAP@@ |
23 | ||
24 | fail "No mapping for $uri ($ENV{USERV_USER})" unless defined $serve_user; | |
25 | ||
26 | $1 = undef; | |
27 | fail "Bad subdirectory $serve_dir" unless $serve_dir =~ m/$repo_regexp/o; | |
28 | our $dir = $1; | |
29 | ||
30 | $dir = "$ENV{HOME}/$dir" unless $dir =~ m|^/|; | |
18c4999f | 31 | |
9ad7f5ed TF |
32 | $dir = "$dir/$repo" if defined $repo; |
33 | $path = $check_export ? "$dir/git-daemon-export-ok" : $dir; | |
34 | fail "$! $path" unless -e $path; | |
35 | syslog 'notice', "$client $dir"; | |
18c4999f | 36 | |
d36c5f7b | 37 | @opts = qw( --strict ) |
e9fec26a TF |
38 | if @opts == 0 and $service eq 'git-upload-pack'; |
39 | ||
40 | my @cmd = ($service =~ m|^(git)-(.*)$|, @opts, $dir); | |
18c4999f | 41 | no warnings; # suppress errors to stderr |
9ad7f5ed | 42 | exec @cmd or fail "exec $service: $!"; |
18c4999f TF |
43 | |
44 | # end |