This a quick and dirty setup of the Subversion version control system on CentOS 5. This setup will use the built in Subversion daemon as opposed to the popular Apache mod_svn module where check in's and check out's are done through http. For more information on Subversion please visit their website linked above or the fantastic free book Version control with Subversion.
This install is done on CentOS Linux 5. These steps should work on almost any Linux distro. It assumes you can install packages with yum from a repository somewhere. It will also let the svn daemon run on it's default port of 3690. Make sure your firewalls are open if you need to get to it remotely. Also, repo is short for Subversion repository.
Login to the machine as root or sudo to root (sudo su -).
Install subversion with yum.
yum install subversion
Make a user and group called svn to run the server as.
adduser -M svn -s /sbin/nologin
Make a directory to store the svn repositories. I'm going to use /disk01/svn in this example.
mkdir -p /disk01/svn
Optional step: Sync a remote svn repository if you have one. If not just move on to the next step.
rsync -av --timeout=30 --delete --rsh="ssh -c arcfour -l root" remotehost:/disk01/svn/ /disk01/svn/
If you did not copy other repos from elsewhere or just want to make another/new one do the following. Put in your repo name where the word repo is.
svnadmin create /disk01/svn/repo
Give the svn user permission to everything in the dir before starting.
chown -R svn: /disk01/svn
Let's start the svn deamon as the svn user. All repos are assumed to be in dir /disk01/svn.
su -m svn -c 'svnserve -d -r /disk01/svn'
That should have started the svnserv daemon. Check your process list (ps -aux |grep svnsrve). If everything worked put that line in the /etc/rc.local file so it will start on start up.
The configuration for each repo is in the file svnserve.conf in each repo's conf dir. It sets the access type allowed to the repo. repo is the name of the repo you want to change the config for.
Edit the file /disk01/svn/repo/conf/svnserve.conf.
The following file is an example of a simple but effective setup. Everyone has anon read access. Only people that have authorized can write. Authorization is done through the repo passwd file using built in authorization (this is discussed next).
[general] anon-access=read auth-access=write password-db=passwd
Save the file. You don't need to restart the daemon for it to take effect.
To add a user to svn you will add them to the Subversion passwd file. This is located in the repo's conf dir. repo is the name of the repo you want to change the password for.
Edit the file /disk01/svn/repo/conf/passwd
The following file is the format of the passwd file. It is just plain text. The format very important. Even a wrong space can mess it up. Make sure there are no spaces between user=password. One user=password per line. Add as many as you want.
[users] user1=password1 user2=password2
Save the file. You don't need to restart the daemon for it to take effect.
Here are some simple commands to test your new repo or possibly ones you copied over from another machine.
Copy a subversion repo directory
svn co svn://hostname/reponame/trunk
List the files in a repo
svn list svn://hostname/reponame/trunk/scripts
Get info on file in repo
svn info svn://hostname/reponame/trunk/scripts/filename
If you want an email update when a repo gets updated you can put this script in the repo's hooks dir. This script will run on each commit. Put the following shell script code into the file /disk01/svn/reponame/hooks/post-commit. Where reponame is the repo you want the emails for. You may have to rename the file in the hooks dir to post-commit as there is usually a default one or you can just make a new one.
REPOS="$1" REV="$2" REPOS_BASE=${REPOS##*/} EMAIL_LIST="[email protected] [email protected] [email protected]" svn log --verbose -r $REV svn://hostname/${REPOS_BASE} | mail -s "Commit notice for repository ${REPOS_BASE}" ${EMAIL_LIST}