Howto Setup a Subversion (SVN) Repository on FreeBSD

This Howto is for installing SVN on FreeBSD using FreeBSD’s ports. SVN is much like CVS and those who have used CVS will be familiar with some of the concepts. I use FreeBSD 6.2 in this guide and create the repositories using the filesytem (fsfs) backend. Mainly this is because I’ve seen errors with the Berkley DB backend option (like so many other articles on the Internet). This is meant to be as simple as possible.

Install SVN with Ports

Enter the ports directory:

cd /usr/ports/devel/subversion 

To compile subversion without the Berkley DB, but with the WebDAV module and the SVN Serve wrapper (used for the SVN+SSH option), use the following:

make -DWITHOUT_BDB -DWITH_MOD_DAV_SVN -DWITH_SVNSERVE_WRAPPER install && make clean

Add a SVN user

First add a group for SVN. Edit

/etc/group 

with your preferred editor, in my case vim and insert an entry like the following:

svn:3690:

Add a user with the username svn:

adduser

When asked questions about the user login, answer yes to login and to the password, however make the password random.

Edit the users umask, so that when it creates files it can be readable/writable by the svn user group:

sudo su -l svn
vim .shrc

make the umask 002, in my case I only had to uncomment a line. Exit the svn user session once finished,

CTRL+D

Create an SVN repository

Typically under FreeBSD

/usr/local

is the normal installation path. However, i like my repository in

/var

, this is mainly due to my partition setup (or slicing in BSD).

mkdir /var/svn && cd /var/svn
svnadmin create myrepo

— myrepo being the name for the repository.

chown -R www:svn /var/svn/

— to make the repository accessible to Apache. Depending on your configuration you may need to link the svn and www groups in /etc/group.
A Subversion repository should now be created. Inside should be a bunch of files and directories.

Configure SSH+SVN Access

Look at this script

/usr/local/etc/rc.d/svnserve

. At the very top you will see some options to add to

/etc/rc.conf

— your needs may differ from the following options added to my setup. A typical entry in

/etc/rc.conf
svnserve_enable="YES"
svnserve_data="/var/svn"
svnserve_user="svn"
svnserve_group="svn"

Start the service with

/usr/local/etc/rc.d/svnserve start

. Now Subversion can be used over SSH.

WebDAV module for SVN, with Apache 2.2

The following entry uses htpasswd for user login and always requires a user, even for checking-out content. This entry can be added to either

/usr/local/etc/apache22/httpd.conf

or in

/usr/local/etc/apache22/extra/httpd-vhosts.conf

:


DAV svn
# any "/svn/foo" URL will map to a repository /usr/local/svn/foo
SVNParentPath /var/svn
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/svn-auth-file
Require valid-user

The leading arrow from the two Location tags are missing as it confuses the code tag in the editor, sorry :(

To allow users to checkout content without a login amend the following to the above Location entry:


Require vaild-user

Again those leading arrows for the LimitExcept tags are missing, :(

Adding Logins for SVN users

With this configuration and many users, it means that many system accounts do not need to be made, providing better security. Typically, the logins would occur over HTTPS to encrypt the password during transit.

To add the first user:

htpasswd -cm /etc/svn_auth_file myuser

Standard way of adding more users:

htpasswd -m /etc/svn_auth_file myseconduser

Now you can restart Apache:

apachectl graceful

Using SVN

Now that the repository has been configured, in this example SVN is running on plain HTTP rather than HTTPS for simplicity, we need to add some content.

To import new content:

svn import my_file http://username@myserver.somewhere.com/svn/myreponame/my_file -m "My Comment"

To checkout content:

svn co http://myserver.somewhere.com/svn/myreponamel/ --username=username

or you can simply browse to the URL in a Web browser and download the files.

To checkin changed content:
Checkout the content and make any changes needed, then:

cd mycheckedout-directory
svn ci

SVN will automatically checkin the content.

The SVN+SSH method is the same bar the URL formation:

svn co svn+ssh://username@myserver.somewhere.com/path/to/repo

However, system user accounts are needed.

I hope this was useful for someone else!

Стырено отсюда http://www.razman.org/?q=node/2

Leave a comment

Please be polite and on topic. Your e-mail will never be published.

You must be logged in to post a comment.