Subscribe to RSS

BASH your SVN and Trac installation!

I’ve already discussed how to install Subversion and Trac on your Ubuntu server. In my case I have a server that manages different SVN and Trac installations for a group of developers.

Creating a new SVN repository and Trac installation every time is quite boring and “if you need to do it more than once, you should automate it”. So, that’s what I did.

The result is the following BASH script. It takes one argument, the name of the project you want to create. E.g if you wanted to create a SVN repository and trac installation for “My Project” you would run the following command:

$ ./create_dev_env my_project

The script it self looks like this:

#!/bin/sh
echo == Creating Subversion and Trac installation for $1
echo  = Creating SVN Repository...
 
# Subversion
cd /var/lib/svn
mkdir -p /var/lib/svn/$1
svnadmin create /var/lib/svn/$1
sed s/EXAMPLE/$1/g /usr/share/trac/contrib/post-commit > /var/lib/svn/$1/hooks/post-commit
chmod +x /var/lib/svn/$1/hooks/post-commit
chown -R www-data:www-data /var/lib/svn/$1
 
# Trac
echo  = Creating Trac install...
cd /var/lib/trac
mkdir -p /var/lib/trac/$1
 
echo  - Creating files
trac-admin /var/lib/trac/$1 initenv $1 sqlite:db/trac.db svn \
/var/lib/svn/$1 /usr/share/trac/templates
 
echo  - Removing anonymous permissions
trac-admin /var/lib/trac/$1 permission remove anonymous  BROWSER_VIEW
trac-admin /var/lib/trac/$1 permission remove anonymous  CHANGESET_VIEW
trac-admin /var/lib/trac/$1 permission remove anonymous  FILE_VIEW
trac-admin /var/lib/trac/$1 permission remove anonymous  LOG_VIEW
trac-admin /var/lib/trac/$1 permission remove anonymous  MILESTONE_VIEW
trac-admin /var/lib/trac/$1 permission remove anonymous  REPORT_SQL_VIEW
trac-admin /var/lib/trac/$1 permission remove anonymous  REPORT_VIEW
trac-admin /var/lib/trac/$1 permission remove anonymous  ROADMAP_VIEW
trac-admin /var/lib/trac/$1 permission remove anonymous  SEARCH_VIEW
trac-admin /var/lib/trac/$1 permission remove anonymous  TICKET_CREATE
trac-admin /var/lib/trac/$1 permission remove anonymous  TICKET_MODIFY
trac-admin /var/lib/trac/$1 permission remove anonymous  TICKET_VIEW
trac-admin /var/lib/trac/$1 permission remove anonymous  TIMELINE_VIEW
trac-admin /var/lib/trac/$1 permission remove anonymous  WIKI_CREATE
trac-admin /var/lib/trac/$1 permission remove anonymous  WIKI_MODIFY
trac-admin /var/lib/trac/$1 permission remove anonymous  WIKI_VIEW
 
echo  - Creating Trac admins
trac-admin /var/lib/trac/$1 permission add ariejan TRAC_ADMIN
 
chown -R www-data:www-data /var/lib/trac/$1
 
echo
echo == Done.

First it creates the SVN directory in /var/lib/svn/my_project and creates repository and adds the trac post-commit hook for trac integration.

Next, it creates the trac installation in /var/lib/trac/my_project and removes all the persmission the anonymous users has. (You may want to remove these lines for open source or public projects.)

And, finally, I’m added as an administrator to the project. Make sure to replace this with you own username.

Hope you find this script useful. Any improvements are welcome, please let me know.

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Technorati
  • BlinkList
  • E-mail this story to a friend!
  • Facebook
  • Live
  • MisterWong
  • Netvouz
  • NewsVine
  • Slashdot
  • SphereIt

5 Comments

  1. Neo
    Posted 20 June, 2007 at 08:38 | Permalink

    Cool stuff!! Thanks Ariejan

    However, can you please explain following two lines in details?

    sed s/EXAMPLE/$1/g /usr/share/trac/contrib/post-commit > /var/lib/svn/$1/hooks/post-commit
    chmod x /var/lib/svn/$1/hooks/post-commit

    Thanks in advance.

  2. Posted 20 June, 2007 at 10:41 | Permalink

    @Neo:

    The sed command takes the post-commit hook file that comes with Trac and replace “EXAMPLE” with the name of your repository name. It then stores it in your Subversion’s ‘hook’ directory.

    When this post-commit file is executable (hence the chmod x), it automatically passes information from the commit you made to Trac. This is what makes the Trac-SVN integration work.

  3. David Goodenough
    Posted 28 June, 2007 at 15:07 | Permalink

    I have the Debian version of trac, and it does not come with a contrib directory. Any pointers as to where I can get this script?

  4. daniel
    Posted 30 June, 2007 at 11:35 | Permalink

    locate post-commit

    In feisty you can find it in:
    /usr/share/doc/trac/contrib/trac-post-commit-hook.gz

  5. Posted 4 December, 2007 at 13:10 | Permalink

    yeah this is cool

One Trackback

  1. [...] directory in ~/projects, it’s going to get tedious. Luckily, Ariejan de Vroom has written a small shell script to automate the procedure. Edit it to your taste, make it executable, supply it with the name of [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*