This is a brief guide on how to set up Subversion with Trac on Apache with commit-mails sent with SVN::Notify Perl module.
First of all, we need to install some software.
# emerge -av subversion apache
When everythin has installed fine, continue.
Create a repository somewhere.
# cd /var/svn/ # svnadmin create test # ll drwxr-xr-x 6 root root 4.0K 2009-01-30 12:56 test
Change the permissions to apache:apache and rights 770:
# chown apache:apache test -R && chmod 770 test -R # ll drwxrwx--- 6 apache apache 4.0K 2009-01-30 12:56 test
Our repository root is at /var/svn/test and our Subversion root is /var/svn.
Two more files are needed if you are doing HTTP Authentication, /var/svn/htpasswd and /var/svn/authz.
Create the htpasswd file with htpasswd2.
# htpasswd2 -c htpasswd username
The authz file looks like this (with the defaults).
[groups] # harry_and_sally = harry,sally [/] username = rw * = # [repository:/baz/fuz] # @harry_and_sally = rw # * = r
Our next step is to configure Apache to work with Subversion.
Open up/etc/conf.d/apache2 and make sure APACHE2_OPTS contains “-D SVN -D SVN_AUTHZ -D PHP5 -D DAV”.
If you’re doing a SVN repository with authentication, I’d advise you to use SVN over SSL (HTTPS).
If we want to use svn.example.com as our Subversion repository URL, our Apache config should look like:
<VirtualHost *:443> ServerName svn.example.com #Include /etc/apache2/vhosts.d/default_vhost.include ErrorLog /var/log/apache2/ssl_error_log <IfModule log_config_module> TransferLog /var/log/apache2/ssl_access_log </IfModule> <Location /> AuthType Basic AuthName "Subversion repository and Trac" AuthUserFile /var/svn/htpasswd Require valid-user SSLRequireSSL DAV svn SVNParentPath /var/svn/ BrowserMatch "SVN" redirect-carefull AuthzSVNAccessFile /var/svn/authz SVNListParentPath on </Location> DocumentRoot "/var/www/localhost/htdocs" </VirtualHost>
If everything is successful, you’ll be able to access your subversion repository at https://svn.example.com/test.
Final touch is the Perl module SVN::Notify. Fire up CPAN.
# cpan cpan shell -- CPAN exploration and modules installation (v1.9301) ReadLine support enabled cpan[1]> install SVN::Notify cpan[2]> install HTML::Entities
Enter your SVN hooks directory.
# cd /var/svn/test/hooks
And copy the post commit template to post commit.
# cp post-commit.tmpl post-commit # vim post-commit
Make sure the following lines are present:
REPOS="$1" REV="$2" export LANG="nb_NO.UTF-8" # optional /usr/bin/svnnotify --repos-path "/var/svn/test" --revision "$REV" --svnlook /usr/bin/svnlook --sendmail /usr/sbin/sendmail --to mail@example.com --from svn@example.com --with-diff --reply-to no-reply@example.com --linkize --handler HTML::ColorDiff --smtp localhost --svn-encoding "UTF-8"
Whenever someone does a commit, a mail with the colored diff is sent out to the recipients.