Automated install of Git host on Ubuntu 10.04 with authorization and web interface for browsing
#!/bin/sh | |
# | |
# install required packages | |
# | |
apt-get install apache2 git-core gitweb | |
# | |
# create folder to host the repositories | |
# | |
mkdir /srv/git | |
# | |
# create apache configuration to serve both the git repos and gitweb under /git | |
# | |
cat > /etc/apache2/conf.d/git << EOF | |
#GIT | |
SetEnv GIT_PROJECT_ROOT /srv/git/ | |
SetEnv GIT_HTTP_EXPORT_ALL | |
ScriptAliasMatch \\ | |
"(?x)^/git/(.*/(HEAD | \\ | |
info/refs | \\ | |
objects/(info/[^/]+ | \\ | |
[0-9a-f]{2}/[0-9a-f]{38} | \\ | |
pack/pack-[0-9a-f]{40}\.(pack|idx)) | \\ | |
git-(upload|receive)-pack))\$" \\ | |
/usr/lib/git-core/git-http-backend/\$1 | |
ScriptAlias /git /usr/share/gitweb/index.cgi | |
<LocationMatch "^/git/.*/git-receive-pack\$"> | |
AuthType Basic | |
AuthName "Git repository" | |
AuthUserFile /srv/git/users | |
Require valid-user | |
</LocationMatch> | |
EOF | |
# | |
# make the necessary symbolic link for gitweb to work properly | |
# | |
ln -s /usr/share/gitweb/gitweb.js /var/www | |
# | |
# create user john (you'll have to provide the password twice here!) | |
# | |
echo "Setting up user 'john'. You'll be prompted to enter John's password twice now." | |
htpasswd -c /srv/git/users john | |
# | |
# create a script to create new repositories (needs to be executed as root!) | |
# | |
cat > /srv/git/create.sh << EOF | |
#!/bin/sh | |
git init --bare \$1.git | |
cd \$1.git | |
git config http.receivepack true | |
git config gitweb.owner "John Doe" | |
cd .. | |
chown www-data:www-data -R \$1.git | |
EOF | |
chmod +x /srv/git/create.sh | |
# | |
# use the create.sh script to create a repository | |
# | |
cd /srv/git | |
./create.sh example | |
# | |
# update parent path for repositories for gitweb | |
# | |
sed -e "s/\/var\/cache\/git/\/srv\/git/" -i /etc/gitweb.conf | |
# | |
# update permissions so that apache can serve the repos | |
# | |
chown www-data:www-data -R /srv/git | |
# | |
# restart apache so that all the changes can take effect | |
# | |
invoke-rc.d apache2 restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
awesome !!!