About purpleidea

I am James. Just James.

git, gitosis, gitweb and friends…

In case it wasn’t already obvious, I am a huge fan of git, and often prefer it over sliced bread. Recently to help a small team of programmers collaborate, I decided to setup a private git server for them to use. By no claim of mine is the following tutorial unique, however I am writing this to aid those who had trouble following other online tutorials.

Goal:
Setup a central git server for private or public source sharing, without having to give everyone a separate shell account.

Step 1:
Install git, gitosis, and gitweb by the method of your choosing. Most distributions probably have packages for all of these.

Step 2:
Create a user account named “git”, “gitosis”, or something sensible if it hasn’t already been done by some packagers install script. The shell command to do this yourself looks something like:

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

In my particular case, I edited the /etc/passwd file to change the automatically added account, however running sudo dpkg-reconfigure gitosis is probably an easier way to do this.

Step 3:
Authentication is done by public ssh key, and gitosis takes care of the magic relationships between a users key and the read/write access per repository. As such, gitosis needs initialization, and it needs the public key of the administrator. If you aren’t familiar with ssh public key authentication, go learn about this now.

To initialize gitosis most tutorials alledge that you should run something like:

sudo -H -u gitosis gitosis-init < SSH_KEY.pub

In my case, this didn’t work (likely due to environment variable problems, but try it first anyways) so I cut to the chase and ran:

sudo su - gitosis
gitosis-init < /tmp/SSH_KEY.pub

which worked perfectly right away. Note that you have to copy your public key to a publicly readable location like /tmp/ first.

Step 4:
Now it’s time to change the gitosis configuration file to your liking. Instead of editing the file directly on the server, the model employed is quite clever: git-clone a special repository, edit what’s necessary and commit, then push the changes back up. Once this is done, git runs a special commit-hook that generates special files needed for correct operation. The code:

git clone gitosis@SERVER:gitosis-admin.git

Step 5:
To add a new repository, and its users, into the machine, the obvious bits are done by making changes in the recently cloned git directory. Once a user has access, setup the new remote, and push.

git remote add origin gitosis@SERVER:the_repository_name.git
git push origin master:refs/heads/master

Subsequent pushes don’t need the master:refs/heads/master part, and everything else should function as normal.

Gitweb:
I still don’t have a happy gitweb+gitosis installation. I’m using apache as a webserver, and I wanted to leave the main /etc/gitweb.conf as unchanged as possible. The gitweb package that I installed, comes with an: /etc/apache2/conf.d/gitweb and all I added was:

SetEnv GITWEB_CONFIG /srv/gitosis/.gitweb.conf

between the <directory> braces. I used the template gitweb configuration file as provided by gitosis.

Gitosis:
The last small change that I needed for perfection is to store the gitweb configuration in the gitosis-admin.git directory. To do this, I added a symlink to /srv/gitosis/repositories/gitosis-admin.git/gitweb.conf from the above gitweb config location. The problem is that the file isn’t in the git repo. This would require patching gitosis to recognize it as a special file, and since the author doesn’t respond to patch offers, and since the gitweb config is usually completely static, I didn’t bother taking this any further.

Gitolite:
It seems there is a well maintained and more fine grained alternative to gitosis called gitolite. The author was very friendly and responsive, and it seems his software provides finer grained control than gitosis. If I hadn’t already setup gitosis, I would have surely investiaged this first.

Etckeeper:
If you haven’t yet used this tool, then go have a look. It can be quite useful, and I only have one addition to propose. It should keep a configurable mapping (as an etckeeper config file) with commands to run based on what gets updated. For example, if I update /etc/apache2/httpd.conf, then run /etc/init.d/apache2 reload.

Happy hacking!

lecturing and git-bisect

I was recently asked to give a lecture for the PRELUDE series at McGill. Here was my abstract:

I don’t like computers, and neither should you.

We spend too much time figuring out how to talk to them, instead of having them figure out how to understand us.

There’s a big discontinuity between what software is providing, and the killer features we want!

We’re not completely lost though. There are a lot of good tools and methodologies available!

Until the feature gap closes, let me introduce you to some of these tools, and show you how I use the computer.

I spoke about a variety of topics with the intention of filling in everyone’s knowledge about the useful tools available to users and developers. I included a section about git-bisect and have posted the script in the examples section of the bash-tutor tarball. It is now available for you to download and share.

I hope everyone enjoyed the lecture, and I always appreciate feedback!

scary cool bash scripting inside a Makefile

Makefiles are both scary and wonderful. When both these adjectives are involved, it often makes for interesting hacking. This is likely the reason I use bash.

In any case, I digress, back to real work. I use Makefiles as a general purpose tool to launch any of a number of shell scripts which I use to maintain my code, and instead of actually having external shell scripts, I just build any necessary bash right into the Makefile.

One benefit of all this is that when you type “Make <target>”, the <target> can actually autocomplete which makes your shell experience that much more friendly.

In any case, let me show you the code in question. Please note the double $$ for shell execution and for variable referencing. The calls to rsync and sort make me pleased.

rsync -avz --include=*$(EXT) --exclude='*' --delete dist/ $(WWW)
# empty the file
echo -n '' > $(METADATA)
cd $(WWW);
for i in *$(EXT); do
b=$$(basename $$i $(EXT));
V=$$(echo -n $$(basename "`echo -n "$$b" | rev`"
"`echo -n "$(NAME)-" | rev`") | rev);
echo $(NAME) $$V $$i >> $(METADATA);
done;
sort -V -k 2 -o $(METADATA) $(METADATA) # sort by version key

The full Makefile can be found inside of the bash-tutor tarball.

getting gedit to work like magic

i use gnu/linux. it’s probably no secret. what is more of a secret, is that i secretly (well actually not so secretly) love using gedit for editing text. i still use vim, echo (gnu bash) and emacs (but only for org-mode).

vim is really, really great. but for day to day full-screen coding, i love working in gedit. i only have one [1] longstanding gripe, and today i believe that it is solved. here is the magic combination which appeases my troubled spirit:

  • gedit smart spaces plugin [2]
  • gedit autotab plugin [3]
  • gedit modelines plugin [4]

install these, restart gedit, enable them, and happy coding!
while it will be much friendlier to use spaces for indentation, i still recommend using tabs, i mean, that’s what the 0x09 was invented for!

[1] actually i wish that everyone would just use eight-space-tabs for all their coding needs, but i realize there are some problems with this, and so i reluctantly am glad that modelines and the above magic exist.

[2] http://git.gnome.org/browse/gedit-plugins/tree/plugins/smartspaces

[3] http://code.google.com/p/gedit-autotab/

[4] http://library.gnome.org/users/gedit/stable/gedit-modelines-plugin.html.en

n900 features that should be added

i decided i’d compile a short list of features / functionality which should be added to the new nokia N900 to make it totally pro. it’s pretty good as it is, despite it not working with the bell networks. i’ve attempted to order this list in order of importance (more or less).

  • all the closed source bits must become free software under a GPL or AGPL license.
  • it should support a fully encrypted file system. if i lose my phone, i shouldn’t worry that all my data or contacts get stolen!
  • addresses that are stored in contacts should integrate with maps program. (currently they only display)
  • the stock maps tool should integrate nicely with the rest of the phone. currently it’s a bit of a sore thumb. confusing too. also it’s green.
  • screen/interfaces should support multi touch.
  • user should be able to choose username instead of default “user”
  • hostname should match bluetooth name, etc… on device, one name.
  • it should support the “usb on the go” host functionality. i’d like to be able to plug in a usb key and be able to copy files to and from it.
  • better battery, if even only an upgrade to the 1500mAh version.
  • once plugged in via usb, it would be nice to be able to unmount as usb device while retaining the charging functionality. currently, when you click on the notification area thing, usb mass storage mode is connected, but there is no software way to disconnect. (that i know of) this is important because you can’t access the files through your phone when mounted.
  • user should be able to specify which accounts notify you of new messages and which don’t. same for which do periodic updates and when.
  • default shell should be bash, not busybox, and it should include usual software like “man”.
  • should include stock ir remote control software, that has a large database of hardware including radios, air conditioners and weird tvs. irreco needs some serious work.
  • people sometimes click on contacts to view data eg a phone number or address to use on a different phone or otherwise. it should be easy to zoom into to read.
  • my gps should just work. (it doesn’t seem to at the moment for some reason)
  • since i change my wireless WEP keys often, and always forget them, the phones wireless manager should integrate nicely with aircrack-ng to easily help me recover my lost WEP key.
  • it could be a little thinner. it’s a bit of a brick as it stands. i could overlook this problem if it did everything above.
  • battery life indicator could benefit from having a countdown timer (sure it would change based on usage, but it would give users an approximate idea)
  • the cameras should be able to function as a usb camera for the computer when the device is plugged in. (over bluetooth could be nice too)

unfortunately i haven’t mentioned this phones positive features– many before me have– there are many! overall it’s a nice package and i look forward to seeing improvements to the above.

a custom epiphany location bar

since i do much research on the internets, i often find myself in a web browser. my favourite of the lot is epiphany. this post isn’t about its merits or failures, but about the awesome way to make my location bar be exactly how i like it: monospaced.

just add the following into your ~/.gtkrc-2.0 file and then restart epiphany. feel free to modify as you wish.


# ~/.gtkrc-2.0
style "Epiphany_Locationbar" {
# leave out the font size if you wish
font_name = "Monospace 12"
#bg[NORMAL] = "#ff0000"
}

# both of these seem to work...
#widget "*.EphyLocationEntry.*" style "Epiphany_Locationbar"
widget_class "*.EphyLocationEntry.*" style "Epiphany_Locationbar"

thanks to raphael for the original post, and the #epiphany developers.