chiark / gitweb /
git-daemon: add Makefile and documentation.
authorTony Finch <dot@dotat.at>
Wed, 31 Mar 2010 02:24:20 +0000 (03:24 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 22 May 2010 14:54:42 +0000 (15:54 +0100)
git-daemon/Makefile [new file with mode: 0644]
git-daemon/README [new file with mode: 0644]
git-daemon/TODO [deleted file]
git-daemon/chiark-urlmap [new file with mode: 0644]
git-daemon/git-service
git-daemon/git-upload-pack.in [moved from git-daemon/git-upload-pack with 77% similarity]
git-daemon/git-urlmap
git-daemon/inetd.conf [deleted file]
git-daemon/inetd.conf.in [new file with mode: 0644]

diff --git a/git-daemon/Makefile b/git-daemon/Makefile
new file mode 100644 (file)
index 0000000..07969cd
--- /dev/null
@@ -0,0 +1,28 @@
+# Makefile for userv-git-daemon
+#
+# This was written by Tony Finch <dot@dotat.at>
+# You may do anything with it, at your own risk.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+include ../settings.make
+
+TARGETS=       git-upload-pack inetd.conf
+
+SUBSTVARS=     libuserv etcuserv
+SEDSCRIPT=     '$(foreach f, $(SUBSTVARS), s,@$f@,$($f),g; )'
+
+all:           $(TARGETS)
+
+%:             %.in
+               sed $(SEDSCRIPT) <$< >$@.new && mv -f $@.new $@
+
+install:       all
+               mkdir -p $(libuserv) $(etcuserv) $(services)
+               cp git-daemon git-service $(libuserv)
+               cp git-upload-pack $(services)
+               cp git-urlmap $(etcuserv)
+
+clean:
+               rm -f $(TARGETS)
+
+# end
diff --git a/git-daemon/README b/git-daemon/README
new file mode 100644 (file)
index 0000000..d8e6a7a
--- /dev/null
@@ -0,0 +1,63 @@
+userv-git-daemon is a replacement for the standard git daemon,
+which provides anonymous remote access to git repositories.
+
+It uses userv to invoke the service requested by the client, and users
+can configure it to map git:// URLs to repositories and enable and
+disable services as they see fit, without intervention from the system
+administrator.
+
+
+To install:
+-----------
+
+Adjust the paths in ../settings.make as necessary.
+userv-git-daemon uses $(libuserv), $(etcuserv), and $(services).
+
+Type make install.
+
+Create a "git" user that will run the outer part of the git-daemon.
+Ensure your /etc/services contains a line like "git 9418/tcp".
+
+Insert the inetd.conf fragment into your /etc/inetd.conf
+and tell inetd to reload.
+
+As a test user, create a 'public-git' directory, and copy a bare git
+repository into it, e.g.
+       git clone --bare git://dotat.at/unifdef.git public-git/unifdef.git
+
+This repository should now be visible:
+       git ls-remote git://localhost/~test/unifdef.git
+
+
+Operation:
+----------
+
+The userv-git-daemon is invoked by inetd which also tells it where to
+find its global git-urlmap script.
+
+The git-daemon parses the request from the network and uses the global
+git-urlmap script to determine which user will run the requested
+service. It invokes userv for the request to be performed. The most
+common service is git-upload-pack, which is confusingly named: it
+uploads from the repository to the network; other services supported
+by git are git-upload-archive and git-receive-pack.
+
+The git-daemon will pass any service beginning git- to userv. The
+userv configuration determines which services may be requested. This
+package includes example git-upload-pack service configurations.
+
+The service configuration uses the git-service script to run the
+service. It passes the global and per-user git-urlmap scripts to the
+git-service script to determine where in the filesyetem the requested
+repository is. Later urlmap scripts override the choices made by
+earlier ones. See the sample git-urlmap script for details of the
+variables they can examine and set.
+
+If a repository is located, the git-service script runs the requested
+service, which is simply the git program with the same name.
+
+
+----------------------------------------------
+This was written by Tony Finch <dot@dotat.at>
+You may do anything with it, at your own risk.
+http://creativecommons.org/publicdomain/zero/1.0/
diff --git a/git-daemon/TODO b/git-daemon/TODO
deleted file mode 100644 (file)
index d47804b..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-userv git daemon todo:
-
-Makefile
-
-documentation!
-
-limit multiple simultaneous invocations with with-lock-ex?
diff --git a/git-daemon/chiark-urlmap b/git-daemon/chiark-urlmap
new file mode 100644 (file)
index 0000000..d3bb876
--- /dev/null
@@ -0,0 +1,27 @@
+# chiark's configuration for the userv git daemon.
+#
+# This was written by Tony Finch <dot@dotat.at>
+# You may do anything with it, at your own risk.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+if ($host eq 'git.chiark.greenend.org.uk') {
+    if ($path =~ m{^~([^/]*)/(.*)}) {
+        $user = $1;
+        $dir = 'public-git';
+        $repo = $2;
+    } else {
+        $user = 'webmaster';
+        $dir = '/u2/git-repos';
+        $repo = $path;
+    }
+} elsif (m{^git://cabal[.]greenend[.]org[.]uk/~([^/]*)/(.*)$}) {
+    $user = $1;
+    $dir = 'cabal-git';
+    $repo = $2;
+} elsif ($host eq 'dotat.at') {
+    $user = 'fanf';
+    $dir = 'public-git';
+    $repo = $path;
+}
+
+# end
index 9661434cc72d2d258cb04679e772723df7f7a30d..aeb4e0e10a397e4c5e2284ba5a5faa237f747898 100755 (executable)
@@ -14,7 +14,7 @@ use Sys::Syslog;
 ${$::{$_}} = $ENV{"USERV_U_$_"}
        for grep s|^USERV_U_([a-z_]+)$|$1|, keys %ENV;
 
-our ($client,$service,$path,$host);
+our ($client,$service,$path,$host,@opts);
 
 openlog "userv-$service", 'pid', 'daemon';
 sub fail { syslog 'err', "$client @_"; exit }
@@ -33,7 +33,10 @@ $path = $check_export ? "$dir/git-daemon-export-ok" : $dir;
 fail "$! $path" unless -e $path;
 syslog 'notice', "$client $dir";
 
-my @cmd = ($service =~ m|^(git)-(.*)$|, '--strict', '--timeout=30', $dir);
+@opts = qw( --strict --timeout-30 )
+   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: $!";
 
similarity index 77%
rename from git-daemon/git-upload-pack
rename to git-daemon/git-upload-pack.in
index 3169ccb5743ae6503decbf1e20ad82a4e31cc201..c66c61c38fbfe82fe6b699cf12ecb45ba585ae4d 100644 (file)
@@ -6,10 +6,11 @@
 
 if ( grep service-user-shell /etc/shells
    & glob service git-upload-pack
+   & glob calling-user git
    )
         reset
        errors-to-syslog daemon error
-       execute /usr/local/lib/userv/git-service /etc/userv/git-urlmap .userv/git-urlmap
+       execute @libuserv@/git-service @etcuserv@/git-urlmap .userv/git-urlmap
 fi
 
 # end
index 61c376cbe9328f4dfc340acb63e825ffa4350202..cf8b55784499a71240ea7052819d62a6b59fdfe5 100644 (file)
@@ -1,27 +1,46 @@
-# Example configuration file for the userv git daemon.
+# Configuration file for the userv git daemon.
 #
 # This was written by Tony Finch <dot@dotat.at>
 # You may do anything with it, at your own risk.
 # http://creativecommons.org/publicdomain/zero/1.0/
+#
+# This is a perl script which is expected to set a few variables
+# to locate the requested repository.
+#
+# REQUEST VARIABLES
+#  $service - normally "git-upload-pack"
+#    `git daemon --help` describes other possible services
+#  $host
+#  $path
+#  $uri     = git://$host/$path
+#  $_       = $uri
+#
+# CONNECTION VARIABLES
+#  $client_addr
+#  $client_port
+#  $client      = [$client_addr]:$client_port
+#  $server_addr
+#  $server_port
+#  $server      = [$server_addr]:$server_port
+#
+# OUTPUT VARIABLES
+#  $user - who runs the service
+#  $dir  - may be:
+#    * an absolute path
+#    * a path relative to the user's home directory
+#    * equivalently, a path starting ~/
+#  $repo - if set, the repository's path is $dir/$repo
+#          otherwise, the repository's path is just $dir
+#  $check_export - whether to check for a git-daemon-export-ok file
+#                  (default false)
+#  $check_repo   - whether to restrict the syntax of $repo
+#                  (default true)
+#  @opts - options for the service command
 
-if ($host eq 'git.chiark.greenend.org.uk') {
-    if ($path =~ m{^~([^/]*)/(.*)}) {
-        $user = $1;
-        $dir = 'public-git';
-        $repo = $2;
-    } else {
-        $user = 'webmaster';
-        $dir = '/u2/git-repos';
-        $repo = $path;
-    }
-} elsif (m{^git://cabal[.]greenend[.]org[.]uk/~([^/]*)/(.*)$}) {
+if ($path =~ m{^~([^/]*)/(.*)}) {
     $user = $1;
-    $dir = 'cabal-git';
-    $repo = $2;
-} elsif ($host eq 'dotat.at') {
-    $user = 'fanf';
     $dir = 'public-git';
-    $repo = $path;
+    $repo = $2;
 }
 
 # end
diff --git a/git-daemon/inetd.conf b/git-daemon/inetd.conf
deleted file mode 100644 (file)
index d4ecf50..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-# Example inetd.conf line for the userv git daemon.
-git stream tcp nowait git /usr/local/lib/userv/git-daemon git-daemon /etc/userv/git-urlmap
diff --git a/git-daemon/inetd.conf.in b/git-daemon/inetd.conf.in
new file mode 100644 (file)
index 0000000..a40382d
--- /dev/null
@@ -0,0 +1,2 @@
+# Example inetd.conf line for the userv git daemon.
+git stream tcp nowait git @libuserv@/git-daemon git-daemon @etcuserv@/git-urlmap