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 | ||
70b9d2e0 | 12 | use POSIX; |
18c4999f TF |
13 | use Sys::Syslog; |
14 | ||
d36c5f7b | 15 | our ($client,$service,$specpath,$spechost,@opts); |
18c4999f | 16 | |
d36c5f7b | 17 | ${$::{$_}} = $ENV{"USERV_U_$_"} |
70b9d2e0 | 18 | for qw(service specpath spechost client); |
18c4999f | 19 | |
70b9d2e0 | 20 | openlog "userv-$service:$ENV{USER}", 'pid', 'daemon'; |
3b32ef57 | 21 | sub fail { syslog 'err', "$client @_"; exit } |
18c4999f | 22 | |
d36c5f7b IJ |
23 | @@READ_URLMAP@@ |
24 | ||
70b9d2e0 | 25 | fail "No user $ENV{USER} mapping for $uri" unless defined $serve_user; |
d36c5f7b | 26 | |
70b9d2e0 | 27 | $serve_dir = "$ENV{HOME}/$serve_dir" unless $serve_dir =~ m|^/|; |
d36c5f7b | 28 | |
70b9d2e0 IJ |
29 | fail "Bad subdirectory $serve_repo" unless $serve_repo =~ m/$repo_regexp/o; |
30 | fail "bad config - repo-regexp does not capture" unless defined $1; | |
31 | my $sani_repo= $1; | |
18c4999f | 32 | |
70b9d2e0 IJ |
33 | my $dir = $serve_dir.(length $sani_repo ? "/$sani_repo" : ''); |
34 | ||
35 | my $path = $check_export ? "$dir/git-daemon-export-ok" : $dir; | |
9ad7f5ed | 36 | fail "$! $path" unless -e $path; |
70b9d2e0 IJ |
37 | |
38 | syslog 'notice', "$client $uri $dir"; | |
18c4999f | 39 | |
d36c5f7b | 40 | @opts = qw( --strict ) |
e9fec26a TF |
41 | if @opts == 0 and $service eq 'git-upload-pack'; |
42 | ||
43 | my @cmd = ($service =~ m|^(git)-(.*)$|, @opts, $dir); | |
18c4999f | 44 | no warnings; # suppress errors to stderr |
9ad7f5ed | 45 | exec @cmd or fail "exec $service: $!"; |
18c4999f TF |
46 | |
47 | # end |