#!/usr/bin/perl # # userv-git-daemon service script # # This was written by Tony Finch and subsequently # heavily modified by Ian Jackson # http://creativecommons.org/publicdomain/zero/1.0/ use strict; use warnings; use POSIX; use Sys::Syslog; our ($client,$service,$specpath,$spechost,@opts); ${$::{$_}} = $ENV{"USERV_U_$_"} for qw(service specpath spechost client); openlog "userv-$service:$ENV{USER}", 'pid', 'daemon'; sub fail { syslog 'err', "$client @_"; exit } @@READ_URLMAP@@ fail "No user $ENV{USER} mapping for $uri" unless defined $serve_user; $serve_dir = "$ENV{HOME}/$serve_dir" unless $serve_dir =~ m|^/|; if (length $serve_repo) { my $inspect= $serve_repo; $inspect =~ s,^/,,; fail "Bad subdirectory $serve_repo" unless $inspect =~ m/$repo_regexp/o; fail "bad config - repo-regexp does not capture" unless defined $1; $serve_repo= "/$1"; } my $dir = $serve_dir.$serve_repo; my $path = $check_export ? "$dir/git-daemon-export-ok" : $dir; fail "$! $path" unless -e $path; syslog 'notice', "$client $uri $dir"; @opts = qw( --strict ) if @opts == 0 and $service eq 'git-upload-pack'; my @cmd = ($service =~ m|^(git)-(.*)$|, @opts, $dir); no warnings; # suppress errors to stderr exec @cmd or fail "exec $service: $!"; # end