Battery Powered

Entries tagged as ‘linux’

Deploying a Git Repository Server in Ubuntu

July 4, 2008 · 4 Comments

Git is a wonderful source code management tool. I’ve been using it now for some weeks of development and I felt ready to deploy my very own repository out on the intarwebs. While there is a lot of documentation available for using git there is also remarkably very little written about the minefield of caveats that is git and Ubuntu. I’ve been trying to create a repository on the server for almost a day until I caved in and resorted to asking people how they did it.

There is currently more than a year old issue on ubuntu, where installing git-daemon-run package clearly does not work. The dependency to runit, which is configured in a rather wrong way, breaks the installation. Unfortunately for us, that means we need to create our own init script that starts up the git-deamon as a service.

As I aim to rectify the situation, let me tell you of a way on how to correctly install a git repo server on a ubuntu machine step-by-step. We need to do the following:

  1. Install gitosis. An easy to use repo manager.
  2. Create an init-file for git-deaemon.
  3. Profit… or maybe not.

What are we waiting for? Let’s get crackin’!

Installing gitosis

Gitosis is a python program that can manage bare git repositories with easy configuration. It also provides some support for git-daemon and gitweb, making the necessary configuration on the repos. The program is fairly easy and straight-forward to install on ubuntu. In fact I did the steps described in this blog post. So I’ll just write a short hand version of that post here. First make sure you have python setup tools installed:

sudo apt-get install python-setuptools

Then grab gitosis by cloning it from original source and into a fresh new workspace. After that we’ll install it.

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

Next make a git user that will manage the git repositories.

sudo adduser \
    --system \
    --shell /bin/sh \
    --gecos 'git version control' \
    --group \
    --disabled-password \
    --home /home/git \
    git

Next copy your public key, i.e the rsa_id.pub file, to the server (e.g. with SCP or something) and add it to the list of authorized keys.

scp <location of id_rsa.pub-file>/tmp
sudo -H -u git gitosis-init < /tmp/id_rsa.pub

Now lets check out the configuration (it is ingeniously stored as a repository of its own in gitosis) and edit it a bit.

git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git
cd gitosis-admin
sudoedit gitosis.conf

You can add custom development groups that can read and write to repositories. For now, just specify a new project and let your user account be the member of that group.

[group test]
members = jdoe@email.com
writeable = test_project
daemon = yes

When the file is saved, and committed to the repository…

commit -a -m "Added group test and test_project in group test."

… then gitosis will create a bare repository automatically. The last parameter, daemon, specifies that git-daemon is free to show the repo in question. So lets try that out:

sudo -u git git-daemon --base-path=/home/git/repositories/ --export-all

You should now be able to access the repository in your local machine such as cloning the project. If you have a firewall, it might be a good idea to port forward the git port to the server. The default port in question is 9418.

Making git-daemon submit to our desires

All is fine and dandy now but the fancy part is making git-daemon run as a service in Ubuntu. As noted earlier if you tried installing the git-daemon-run package you will notice that it won’t work. Instead we’ll have to write our own damn init script. So lets start with creating the right file for the init script at /etc/init.d/git-daemon.

sudo edit /etc/init.d/git-daemon

And paste the following script at this pastie link (thanks to fujin on #git @ Freenode IRC for providing the pastie). But change the DAEMON_OPTS line so it includes the correct base-path and export-all attributes, like this:

DAEMON_OPTS="--base-path=/home/git/repositories --verbose --syslog
--detach --pid-file=$PIDFILE --user=git --group=nogroup --export-all"

All that is left is to change modes and run the darn service.

sudo chmod +x /etc/init.d/git-daemon
sudo invoke-rc.d git-daemon start

You should now be able to do your git stuff with your server at a git://yourserver/your_repo.git addy. I hope this has helped you out to run your very own git repository server.

Categories: dev
Tagged: , , ,

Howto: Alias in Ubuntu (or I CAN HAS ALIAS)

June 13, 2008 · Leave a Comment

When you found this blog post you were probably fed up with repeating some really difficult-to-write commands. You’ve probably heard of this alias command from somewhere and decided to look it up on your favorite search engine. Look no further my good man… or woman… because I will tell all you will need in few minutes of your time. The basic command for binding one new command to replace the old one looks like this:

alias new_command='old_command'

Just typing alias into your shell will list all bindings available for you. If you have Ubuntu like me, the default output should look like this:

$ alias
alias ls='ls --color=auto'

As an example, let us amend on what a windows admin geek griefs about the most when using linux. We’ll bind the well known windows dir command with the common one that your linux computer uses.

$ alias dir='ls'

Whenever you type in dir the bash shell will look up the alias and execute the old command. But because you who are most likely a wannabe Linux geek who wants to phase out of the windows world we’ll remove that stupid binding and test it:

$ ualias dir
$ dir
bash: dir: command not found

The binding should now be removed and your bash shell should not know what the command dir is. Whenever you’re binding useful commands and you restart your shell, the bindings will reset. In order to retain the changes you’ll need to edit your bashrc file and add the commands there. If you have Ubuntu like me you might want to do the following. Go to your home directory and fire up your favorite editor.

$ cd ~
$ nano .bashrc

Further down the file you will find the alias definitions and there you will find a commented if-statement. The default configuration suggests you add your bindings to the bash_aliases file. So let us first uncomment those lines like this:

# Alias definitions.
# ...
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Save, exit and start editing the bash_aliases file which will most likely be a new file.

$ nano .bash_aliases

And add your bindings in that file. So now you know how to add alias definitions and change your bash configuration to retain them. Of course you can do some really funny meowy things with this:

I can has Sudo!

The primary reason for me to write this blog post is because during an IRC chat I found out about a unix geek who bound some lolcat commands. Such as the:

alias plz=sudo

The power of this alias binding is in it’s innocently intrinsic humor:

$ plz adduser Cat
$ plz umount kittypictures

I’m pretty sure that you can invent some much more funny alias bindings yourself.

Categories: dev
Tagged: , , , ,