The Complete Step-by-Step Guide to Installing Gitosis (Part 1)

 

This turned out to be such a long article I've split it into two parts. The first deals with setting up Gitosis, and Part 2 will cover creating and managing repositories.

Here at Foxsoft we use Git for version control. We wanted somewhere we could push our repositories to that would be backed up regularly because, well, you can never have too many backups. We use a mac mini as a CI server so it seemed an ideal place to hold the Git repositories too.

The instructions are mostly the same for both Tiger and Leopard, you just need to do a few more steps with Tiger because the version of Python that Apple included in Tiger is a bit old.

Download and Install Python

The easiest option is to just go and download Python 2.5 from http://python.org/download/releases/2.5.4/, you should find a universal installer dmg. Just install that.

Then you’ll need to get the Python setup tools module. Now apparently it’s included in the binaries we just downloaded but Gitosis still moaned that they were missing for me so I got the egg from http://pypi.python.org/pypi/setuptools. The one I downloaded was setuptools-0.6c9-py2.5.egg. (You might need to make sure it ends in .egg when you’ve downloaded it.) Then run it with something like:

sudo sh setuptools-0.6c9-py2.5.egg

Leopard Users Start Here

Hello Leopard users. Thanks for joining us, you lucky ducks have a more up to date version of Python so you don’t need to go through any of that nonsense.

Ok, now we need to download and install gitosis on the machine that’s going to host the repositories.

Hopefully you’re familiar with the Terminal; we’re going to use it a lot. So open Terminal and make a directory to build gitosis1 in.


    mkdir src
    git clone git://eagain.net/gitosis.git
    cd gitosis
    sudo python setup.py install

Next we need to find an unused uid and gid


    sudo dscl . list /Users uid
    sudo dscl . list groups gid

Check the list of numbers that get returned and find an unused one. I used 401 and most likely that’ll be free for you too.

Next we need to create the git user and group using that number. You can call it anything but git is an obvious choice. Also, we need to decide where we’re keeping the repositories. It makes sense to store it in the users home directory.


    sudo dscl . create groups/git
    sudo dscl . create groups/git gid 401

    sudo dscl . create users/git
    sudo dscl . create users/git uid 401
    sudo dscl . create users/git NFSHomeDirectory /Users/git
    sudo dscl . create users/git gid 401
    sudo dscl . create users/git UserShell /bin/bash
    sudo dscl . create users/git Password '*'

Then create the home directory


    sudo mkdir /Users/git
    sudo chown git /Users/git
    sudo chgrp git /Users/git

Git and Gitosis use SSH to communicate so you need an SSH key. Now on your computer, not the server, create a key with

ssh-keygen -t rsa

if you don’t have one, then copy the public key portion to the server

scp ~/.ssh/id_rsa.pub your_server:/tmp/your_name_key.pub

Don’t forget to replace your_server and your_name with their obvious values.

In case you hadn’t guessed, and let’s face it you probably haven’t :), we’re doing this because you’re going to be the only user that gitosis knows about to begin with and hence administer it. Congratulations.

Ok, now back into the server’s Terminal to setup gitosis


    cd /Users/git
    sudo -H -u git gitosis-init < /tmp/your_name_key.pub

    sudo su git
    echo "export PATH=$PATH" > ~/.bashrc
    exit

If you’re using Git 1.6+, like we are, then you need to change the echo line to read:

export PATH=$(git --exec-path):$PATH

Gitosis does it’s work through Git’s post-update hook so make sure it’s executable

sudo chmod 755 /Users/git/repositories/gitosis-admin.git/hooks/post-update

Finally, back on your local machine clone the gitosis-admin repository

git clone git@your_server:gitosis-admin.git

Replace your_server as appropriate (and also git@ if you chose not to use git as the username, e.g. foobar@your_server:gitosis-admin.git)

If all goes well and you get a repository, chances are good that things are working!

Come back tomorrow for Part 2 where we'll be actually getting some repositories added to the server.

1 http://eagain.net/gitweb/?p=gitosis.git