Subversion + Trac for Multiple Projects (One Click Build)

The Problem

If you are wondering why exactly you need version control, then you should probably read this. Subversion is a great open-source version control system. And Trac is a good project management and bug/issue tracking system which works seamlessly with Subversion. The problem is how to create and manage multiple projects using a single build procedure.

Subversion + Trac

The Solution

First we need a machine running Ubuntu. The steps below have been tested for Ubuntu 8.04.

Launch terminal and run the following command to install Apache, Python and Subversion.

sudo apt-get install apache2 libapache2-mod-python libapache2-svn python-setuptools subversion python-subversion

You can use sudo apt-get install Trac, but the version it installs is 0.10.4. Inorder to get the latest version of Trac use the following command. I suggest you specify the latest stable version of Trac in the command line. As of writing this guide, it is 0.11.3. Also, execute the commands below i.e. create directories svn and trac; create a htpasswd file with your usernames.

sudo easy_install http://ftp.edgewall.com/pub/trac/Trac-0.11.3.tar.gz
sudo mkdir /svn
sudo mkdir /trac
sudo htpasswd -cm /etc/svnauth yourusername
sudo htpasswd -m /etc/svnauth nextusername

Next you have to create a file for permissions

sudo gpedit /etc/svnaccess

Add the following contents to the file. Make sure you change yourusername and nextusername to the usernames you have created.

developers = yourusername, nextusername	 
[ / ]
@developers = rw	 
* = r

Then you have to create a new configuration file for Apache by executing:

sudo gedit /etc/apache2/sites-available/myserver

Add the following contents to the file. Make sure you change [email protected] to you email address.

<VirtualHost *>

	ServerAdmin [email protected]
	DocumentRoot /var/www/
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	<Directory /var/www/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all

	ErrorLog /var/log/apache2/error.log
	LogLevel warn
	CustomLog /var/log/apache2/access.log combined
	ServerSignature On

<Location /svn>

   DAV svn
   SVNParentPath /svn

   AuthType Basic
   AuthName "Subversion Repository"
   AuthUserFile /etc/svnauth
   Require valid-user

   AuthzSVNAccessFile /etc/svnaccess

<Location /trac>

   SetHandler mod_python
   PythonHandler trac.web.modpython_frontend
   PythonOption TracEnvParentDir /trac
   PythonOption TracUriRoot /trac

   AuthType Basic
   AuthName "Trac"
   AuthUserFile /etc/svnauth
   Require valid-user



Once that is done, activate your newly created configuration file by using the a2ensite command as follows. Reload Apache, set permissions and edit trac.ini.

sudo a2ensite /etc/apache2/sites-available/myserver
sudo /etc/init.d/apache2 reload
sudo chown -R www-data /trac
sudo gpedit /etc/trac.ini

Add the following contents to trac.ini.

alt = Logo
height = -1
link = 
src = /logo.gif
width = -1

/etc/trac.ini will store the default configuration for each Trac project instance. Copy your logo.gif to /var/www folder.

Finally, create a perl file called init.pl and add the following contents. Make sure you change yourusername to your username. This step will grant you administration rights so that you can add milestones etc. straight from the web interface.

$sName = $ARGV[0];
$lName = $ARGV[1];
if ($lName eq "") {
   $lName = $sName;
$sName =~ tr/A-Z/a-z/;
$path = "sudo svnadmin create /svn/$sName";
system ($path);
$path = "sudo chown -R www-data /svn/$sName";
system ($path);
$path = "sudo trac-admin /trac/$sName initenv '$lName' 'sqlite:db/trac.db' 'svn' '/svn/$sName' --inherit=/etc/trac.ini";
system ($path);
$path = "sudo chown -R www-data /trac/$sName";
system ($path);
$path = "sudo trac-admin /trac/$sName permission add yourusername TRAC_ADMIN permission list yourusername";
system ($path);
print "Done!\n\n";

Once the above file is created, your one click build is ready!

Now every time you want to create a new project, all you have to do is execute:

init.pl ‘shortprojname’ ‘fullprojname’

where shortprojname is the name of your project with no spaces e.g. todoapp
fullprojname is the expanded name of your project e.g. To-Do Application

Create your first sample project and point your browser to http://localhost/trac/shortprojname for Trac
The path for your SVN repository will be http://localhost/svn/shortprojname

If you are looking for a GUI client for Subversion, I suggest you download TortoiseSVN for Windows or Versions for Mac. If you are not sure on how to use TortoiseSVN, here are a couple of tutorials.

Feel free to let me know if there are any suggestions or comments you have. To learn more about Subversion, do take time off to read the Subversion Book.

718 Words