Otaqui.com Blog

Bash Script for Serving Multiple Trac Projects and Sharing Authentication

I use Trac for personal projects, and I share some of these out with people as required. I use tracd (TracStandalone) for this, rather than a full-blown apache setup, since it serves my needs quite nicely and is a lot easier to turn on and off as required without tweaking apache config and rebooting the whole webserver.

All my projects live under a single parent directory, and I prefer to share a single users digest file between them all – so ideally I wanted to share a single tracd to run all my projects. This is fairly straightforward on the command line:

tracd --hostname=webhost.com -p 9876 \
--auth="*,/path/projects/people.htdigest,Realm" \
/path/projects/p1 \

That is ….
Line 1 – start tracd for a given hostname and port,
Line 2 – specify auth for all projects (*), the auth file and the “Realm” you specified when creating the file with apache’s htdigest command
Lines 3+ – specify as many projects as you want to run

This is ok with a couple of projects, but gets unwieldy quite quickly. What I needed was a little shell script to open up all projects under a given directory quickly. Here’s what I came up with:

# make / truncate a temp file to store names:
> $temp
# specify base directory:
# output all subdirectories to temp file:
find $base -maxdepth 1 -mindepth 1 -type d \
-exec echo -n "{} " > $temp \;
# now start tracd
tracd --hostname=webhost.com -p 9876 \
--auth="*,/path/projects/people.htdigest,Realm" \
`cat $temp`

Essentially this script uses ‘find’ to get all of the directories exactly 1 level down from your projects directory, and will echo their paths to a temp file (suppressing the newlines). It will then run run tracd, appending the contents of this file to the end of the call.