#!/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 Sys::Syslog; our ($client,$service,$specpath,$spechost,@opts); ${$::{$_}} = $ENV{"USERV_U_$_"} for qw(service path host) openlog "userv-$service", 'pid', 'daemon'; sub fail { syslog 'err', "$client @_"; exit } @@READ_URLMAP@@ fail "No mapping for $uri ($ENV{USERV_USER})" unless defined $serve_user; $1 = undef; fail "Bad subdirectory $serve_dir" unless $serve_dir =~ m/$repo_regexp/o; our $dir = $1; $dir = "$ENV{HOME}/$dir" unless $dir =~ m|^/|; $dir = "$dir/$repo" if defined $repo; $path = $check_export ? "$dir/git-daemon-export-ok" : $dir; fail "$! $path" unless -e $path; syslog 'notice', "$client $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