#!/bin/dash BASE='/home/dkl9/private/git.repostorage' REPO="${REQUEST_URI#/git/}" REPO="${REPO%%/*}" REPO=`echo "$REPO" | tr -cd 'a-zA-Z0-9._-'` MATCH=`ls "$BASE" | grep "^$REPO" | head -n 1` if [ -n "$MATCH" ] then export GIT_PROJECT_ROOT="$BASE/$MATCH" export GIT_HTTP_EXPORT_ALL=1 export PATH_INFO="${REQUEST_URI#*/$REPO}" export PATH_INFO="${PATH_INFO%%\?*}" if [ -z "$PATH_INFO" ] then printf 'Status: 200 OK\nContent-Type: text/plain\n\n' printf '%s is a git repository.\n' "$MATCH" printf 'Browse it online at\nhttps://%s/%s\n' 'git.dkl9.net' "$MATCH" printf 'Clone it with\ngit clone https://%s/git/%s\n' 'dkl9.net' "$MATCH" elif [ -r "$GIT_PROJECT_ROOT" ] then exec /usr/lib/git-core/git-http-backend else printf 'Status: 403 Forbidden\nContent-Type: text/plain\n\n' printf '%s is a git repository here, but the server cannot read it\n' "$MATCH" fi else printf 'Status: 404 Not Found\nContent-Type: text/plain\n\n' printf 'No repository found matching %s\n' "$REPO" fi