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 | |
9bbb6177 IJ |
29 | if (length $serve_repo) { |
30 | my $inspect= $serve_repo; | |
31 | $inspect =~ s,^/,,; | |
32 | fail "Bad subdirectory $serve_repo" unless $inspect =~ m/$repo_regexp/o; | |
33 | fail "bad config - repo-regexp does not capture" unless defined $1; | |
34 | $serve_repo= "/$1"; | |
35 | } | |
36 | ||
37 | my $dir = $serve_dir.$serve_repo; | |
70b9d2e0 IJ |
38 | |
39 | my $path = $check_export ? "$dir/git-daemon-export-ok" : $dir; | |
9ad7f5ed | 40 | fail "$! $path" unless -e $path; |
70b9d2e0 IJ |
41 | |
42 | syslog 'notice', "$client $uri $dir"; | |
18c4999f | 43 | |
d36c5f7b | 44 | @opts = qw( --strict ) |
e9fec26a TF |
45 | if @opts == 0 and $service eq 'git-upload-pack'; |
46 | ||
47 | my @cmd = ($service =~ m|^(git)-(.*)$|, @opts, $dir); | |
18c4999f | 48 | no warnings; # suppress errors to stderr |
9ad7f5ed | 49 | exec @cmd or fail "exec $service: $!"; |
18c4999f TF |
50 | |
51 | # end |