This was originally posted on 2009-04-16 to http://andrewho.co.uk/weblog/installing-cgit-on-a-joyent-shared-accelerator-solaris
I recently found the time to setup a web frontend to git on my Shared Accelerator. Pretty much all of my data (including work) is under version control so this is useful for those occasions when I'm away from my own computer but want to fetch a file. I went with cgit rather than gitweb because the configuration looked cleaner and more powerful; it also (utterly unscientifically) felt a lot more responsive (it is meant to be, especially once you enable the cache). The installation proved to be less trivial than I expected upon first inspection, hence this documentation.
The first step is to fetch the cgit source and get it ready for compilation. I
did this in ~/tmp
.
% git clone git://hjemli.net/pub/git/cgit
% cd cgit
% git submodule init
% git submodule update
Edit the configuration variables at the top of the Makefile
. Pretty much the
most important variable is CGIT_CONFIG
; here's my configuration:
CGIT_VERSION = v0.8.2.1
CGIT_SCRIPT_NAME = cgit.cgi
CGIT_SCRIPT_PATH = /users/home/andrewlkho/cgi-bin
CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
CGIT_CONFIG = /users/home/andrewlkho/etc/cgitrc
CACHE_ROOT = /users/home/andrewlkho/var/cache/cgit
SHA1_HEADER = <openssl/sha.h>
GIT_VER = 1.6.1.1
GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
INSTALL = install
There are some syntax oddities that Solaris' /bin/sh
doesn't like, so the
easiest thing to do is change the interpreter to /usr/local/bin/bash
. This
only applies to gen-version.sh
.
#!/usr/local/bin/bash
...
Solaris doesn't have timegm
(a non-standard GNU extension) so we need to
apply this
patch
from Apple. Place the following code somewhere near the top of ui-stats.c
.
#include <time.h>
#include <stdlib.h>
time_t timegm (struct tm *tm) {
time_t ret;
char *tz;
tz = getenv("TZ");
setenv("TZ", "", 1);
tzset();
ret = mktime(tm);
if (tz)
setenv("TZ", tz, 1);
else
unsetenv("TZ");
tzset();
return ret;
}
Finally, compile cgit and copy the relevant files into place.
% LDFLAGS="-lnsl" NO_STRCASESTR=yes NO_ICONV=yes CC=gcc \
> gmake
% mkdir ~/web/public/git
% cp cgit ~/cgi-bin/cgit.cgi
% cp {cgit.css,cgit.png} ~/web/public/git
The next step is to configure cgit. The
manpage documents all of the
configuration variables, but to get you off the ground the following will
suffice. I've only entered one (bare) repository, but you can repeat those
lines as many times as you want for more repositories. Remember, this is in
~/etc/cgitrc
css=/git/cgit.css
logo=/git/cgit.png
repo.url=bin
repo.path=/users/home/andrewlkho/git/bin.git
repo.desc=A bunch of useful scripts for my ~/bin
We now have a fully working cgit setup; just navigate to your equivalent of
http://andrewho.co.uk/cgi-bin/cgit.cgi
and browse away.
Whilst that's all fine and dandy, I wanted a slightly more semantic path to the
interface. This isn't as easy it sounds due to the fact that mod_vd
and
mod_rewrite
simply don't play together in any nice well-documented way. To
save you quite a bit of grief, I'll just present the final result.
This is what ~/etc/cgitrc
now looks like:
virtual-root=/
css=/cgit.css
logo=/cgit.png
repo.url=bin
repo.path=/users/home/andrewlkho/git/bin.git
repo.desc=A bunch of useful scripts for my ~/bin
The following is in ~/web/public/.htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^git\.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]
RewriteCond %{HTTP_HOST} ^git\.
RewriteRule ^git/$ /cgi-bin/cgit.cgi [L]
RewriteCond %{HTTP_HOST} ^git\.
RewriteRule ^(.*)$ /cgi-bin/cgit.cgi?url=$1 [L,QSA]
Now if you fire up your equivalent of http://git.andrewho.co.uk/
you should
have a bunch of slightly nicer URLs to navigate through. Enjoy!