Created
November 18, 2013 12:32
-
-
Save phillipberndt/7527071 to your computer and use it in GitHub Desktop.
A push-enabled GIT configuration for Apache / cgi-bin / public-html. Place both files in your `public_html` folder, create a corresponding `.htpasswd` file & enjoy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AddHandler cgi-script .cgi | |
<Files "git.cgi"> | |
Require valid-user | |
AuthType Basic | |
AuthName "GIT Access" | |
AuthUserFile /path/to/.htpasswd.git | |
</Files> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Configuration: | |
# The base directory for your repositories, must be writable for the server | |
GIT_PROJECT_BASE=/path/to/git/ | |
# A mail address to send reports on new repositories to | |
MAIL=pberndt | |
INFO=(`echo ${PATH_INFO} | sed -nre 's#^/([^/\.]+)(/.+)?#\1 \2#p'`) | |
REPOSITORY="${INFO[0]}" | |
export PATH_INFO="${INFO[*]:1}" | |
if [ -z "$REPOSITORY" -o "$PATH_INFO" = "/" ]; then | |
cat <<EOF | |
Status: 200 Ok | |
Content-type: text/html; charset=utf-8 | |
<h1>GIT repositories</h1> | |
<p> | |
Welcome to this GIT repository hub. You seem to have accessed this page | |
from your web browser. That's not how it's done. See <a | |
href="http://git-scm.com/book/">http://git-scm.com/book/</a> for an | |
introduction to GIT. | |
</p> | |
<p> | |
To access these repositories, clone them using git: | |
</p> | |
<pre> | |
git clone http://${REMOTE_USER}@${SERVER_NAME}${SCRIPT_NAME}/${REPOSITORY:-<repository name>}/ | |
</pre> | |
EOF | |
exit | |
fi | |
export GIT_PROJECT_ROOT=${GIT_PROJECT_BASE}/${REPOSITORY} | |
export GIT_HTTP_EXPORT_ALL=1 | |
if ! [ -d "$GIT_PROJECT_ROOT" ]; then | |
if ! mkdir $GIT_PROJECT_ROOT; then | |
echo -e "Status: 404 Not found\r\n" | |
exit | |
fi | |
(cd $GIT_PROJECT_ROOT && git init --bare && git update-server-info && mv hooks/post-update.sample hooks/post-update) >/dev/null | |
env | mail -s "New git repositoy $REPOSITORY created in public_html" $MAIL | |
fi | |
exec git http-backend |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment