Jan 092012
 

One of the easiest ways to set up a subversion server that is lightweight is to use an existing linux server with sufficient free space available to hold your repositories.  This is much more lightweight because it really doesn’t require any additional software or services, outside of subversion which is likely already installed if you use the svn client; and ssh which is probably already installed and running.

I will give the steps I used for centos, but it will work with other linux distributions if you apply the correct package management steps (pacman, apt-get, yum, emerge, etc):

First, make sure we have subversion and openssh installed:

yum install subversion openssh-server

Decide where you are going to hold your subversion repositories.  I decided to use /home because those directories already get backed up nightly.  Once you decide where you wish them to be, run the following commands to set up your first repository called stuff:

mkdir /home/svn
mkdir /home/svn/stuff
svnadmin create /home/svn/stuff

Set up an svn group for the users allowed to use svn:

groupadd svn

Give the group ownership of the repository and set the permissions for the group to have read and write access:

chown -R :svn /home/svn
chmod -R 775 /home/svn

Add users to the group who need access to the svn repositories:

useradd -G svn username

Create a wrapper script inside of your repo directory, mine is /home/svn/svnwrapper.sh

#!/bin/sh 
 
# set the umask so files are group-wriable
umask 002
 
# call the 'real' svnserve, also passing in the default repo location
exec /usr/bin/svnserve "$@" -r /home/svn

Make sure the script is executable:

chmod 775 /home/svn/svnwrapper.sh

Create a symbolic link from /usr/local/bin/svnserve to the wrapper script (modify for the correct path you used):

ln -s /home/svn/svnwrapper.sh /usr/local/bin/svnserve

Create a maintenance script to help you set up additional svn repositories.  I create mine in /usr/local/bin/makesvn.sh:

#!/bin/bash
 
# By Ed Wiget
# This sets up a new subversion repository
 
# this defines the home path
homesvn=/home/svn
 
# this defines the name to create, i.e. entering laptop will create /home/svn/laptop
echo "What is the name to set up?"
read svnname
 
if [ -d ${homesvn}/${svnname} ]; then
	echo "name already exists....exiting"
	exit
else
	echo "setting up ${homesvn}/${svnname}"
	svnadmin create ${homesvn}/${svnname}
	mkdir -p ${homesvn}/${svnname}
	mkdir -p ${homesvn}/${svnname}/trunk
	mkdir -p ${homesvn}/${svnname}/tags
	mkdir -p ${homesvn}/${svnname}/branches
	chown -R root:svn ${homesvn}/${svnname}
	chmod -R 775 ${homesvn}/${svnname}
	echo -e "done.....\n\nyou may now set your initial checkin using\nsvn import ${svnname} svn+ssh://USERNAME@SERVER/${svnname} -m 'inital import'"
fi

The set up is now done on the server side.  On the client side, import the initial data:
svn import stuff svn+ssh://USERNAME@SERVER/stuff -m ‘inital import’

Anytime you need to set up a new svn repo, simply run /usr/local/bin/makesvn.sh and it will create the svn repo, create the folders, and set up the correct permissions.

Part of this tutorial was borrowed from http://www.startupcto.com/server-tech/subversion/setting-up-svn

This site uses Akismet to reduce spam. Learn how your comment data is processed.