Step-by-step guide to installing Subversion

From SynologyWiki
Jump to: navigation, search

This guide will use the Subversion server svnserve in inetd spawned mode.


Contents

Install Subversion Server

Enable CLI on your Diskstation

See Overview: What is CLI, how do I access it, SSH or Telnet?.

Create a user for svnserve daemon

For security reasons it is a good idea to create a separate user just for the Subversion daemon. Use the MUI under Privileges -> User to create a new user. In this guide I will be using svnowner. Give this user a complicated password, which we actually do not need to remember, as we will just spawn svnserve daemon with this user account from inetd, so just set it to some value (for security reasons to something other than the empty value).


Create a new share for your repositories

This step is optional, but is a good idea to keep the management more straightforward. Use the MUI under Privileges -> Shared Folder to create a new shared folder. In this guide I will be using svn. Be sure to give admin and svnowner read-write permissions and remove all rights from the rest of the users.


Install the ipkg bootstrap

We need to install the ipkg bootstrap to be able to easily install the Subversion Package from the OptWare feeds. See the Bootstrap section in Overview on modifying the Synology Server, bootstrap, ipkg etc

Install Subversion Package

Now that you have installed ipkg we can install the Subversion Package from the Command Line Interface. Issue:

ipkg install svn

The ipkg will also install some dependencies (other required packages), which is normal and desired.


Configure Unix inetd daemon to spawn Subversion when required

I chose to use inetd method instead of running svnserve as daemon (see SVN Book under server configurations for more information about svnserve modes), as in this case the Unix inetd daemon will temporarily spawn svnserve whenever a request comes in on port 3690 (IANA-Subversion). This method uses the limited amount of RAM in Diskstation for Subversion only when required. Disadvantage over standalone svnserve daemon mode is that it takes a bit more time during client connect, as each time first the svnserve needs to be loaded into RAM.

For adding Subversion to inetd, we need to edit the inetd configuration file /etc/inetd.conf. For mods we will use somewhat unintuitive (specially for Windows users) text-editor vi from 1976 as this is the only editor already installed on the Synology. vi key-mapping can be seen here. Following the detailed instructions below requires no previous vi knowledge.

First open the file in vi with:

vi /etc/inetd.conf

Press Shift+a to append to end of line. Press Enter for a newline and enter following text all in a single line:

svn stream tcp nowait svnowner /opt/bin/svnserve svnserve -i -r /volume1/svn

Be sure to match the username svnowner and the repository directory /volume1/svn to your customizations if you did choose something other than the examples in the beginning of this guide. Press ESC to quit the insert mode. Type:

:wq

to write the file to disk and quit vi.


Edit /etc/services to include Subversion data

Add the following 2 lines to your /etc/services file (see step 11 for vi instructions):

svn 3690/tcp # Subversion 
svn 3690/udp # Subversion

Be sure to save your changes with:

:wq


Reboot

Issue:

reboot

Subversion should be running on your Diskstation now. Below are some further tips on how to access and test the functionality of Subversion.


Test the operation of Subversion on your Diskstation

Create SVN Repository

Log into your Diskstation with SSH and root account. Change your personality to user svnowner with:

su svnowner

Notice: If you experience an error like su: cannot run /sbin/nologin: No such file or directory you should look here: Changing the login shell for a user.

Create under /volume1/svn a new repository with:

cd /volume1/svn 
svnadmin create test

(Naturally test can be substituted with some other name you like.)

Notice, that a directory (with Subversion management content) named test is created. You can check this for example with command:

ls -la

Set repository permissions

Under /volume1/svn/test/conf you will find repository configuration files, interesting for us at the moment are only passwd and svnserve.conf. For testing edit the passwd file to have following contents:

[users] 
testuser = testpw

Notice that the password will be written in clear-text in this file, so for security reasons you might want NOT to use the same credentials as you use in your system as a login account (although if you make sure with chmod 600 passwd that only the user svnowner can access the file, the risk of someone being able to sneak a peak without administrative account or knowing the svnowner password is minimal).

Edit also the svnserve.conf to have following contents:

[general] 
anon-access = none 
auth-access = write 
password-db = passwd 
realm = I am your test repository

This will disable anonymous access completely. If you want people to access your repo without any authentication, use following line instead to give anonymous users just read access:

anon-access=read

or to give everybody full access (not really recommended for other than just testing):

anon-access=write


Checkout the repository

Make sure you have svn client tools installed on your computer. In command line issue:

svn co svn://<IP of your Diskstation>/test <some localfolder>

When asked password for svnowner press just Enter. Input username: testuser and password: testpw as defined in file passwd.

Windows users might consider using TortoiseSVN, which will integrate Subversion client functionality into Windows Explorer. After installation and requested reboot just right click in an empty place in Windows Explorer and choose SVN Checkout... Your repository Path (URL of repository) is:

svn://<IP of your Diskstation>/test

In Checkout directory type a path to a new non-existing or empty directory. Leave the other options to their defaults and click OK. You will be asked for a username and password, these are according to file /volumes1/svn/test/conf/passwd testuser and testpw accordingly.

You should have successfully checked out the revision 0 of the repository. Click OK to dismiss the dialog.


Add a new file and commit it

To check that you can also commit into the repository, add a new file under the newly created repository.

In Unix, Linux and Mac this test could be performed like this:

cd /<localfolder, where you checked out the repository>
echo "I am a Test" > test.txt
svn add test.txt
svn ci -m "Commit test"

Enter the credentials testuser and testpw accordingly.

To check commiting with TortoiseSVN under Windows you should first create or copy a sample file into the directory, which you checked out in last step. Add the new file under revision control by right-clicking it and selecting TortoiseSVN -> Add. Commit the changes by right clicking on the repository directory and choose SVN Commit...

Enter the optional, but recommended message (commit description) and click OK. Enter the credentials testuser and testpw accordingly.

You should get a commit success message Completed. Click OK to dismiss the dialog.

For more information please see the Subversion Book.


Remove test repository

To delete the test repository, SSH to your Diskstation and delete the folder /volume1/svn/test. It can be achieved with following command:

rm -rf /volume1/svn/test

Your local working copy folder, which you checked out, can be simply deleted.

How to use SVN over SSH for added security and encryption

This method works fine, though it will be slower than a direct TCP connection to the server. Additionally, the server is also spawned on each connection, but you also have the added overhead of the ssh connection.

  • No need to perform all the reboots. This not a windows machine
  • Do not make changes to initd
  • Do not follow instructions under Set repository permissions
  • After installing svn, create symlink as root
ln –s /opt/bin/svnserve /usr/bin/svnserve
  • edit /etc/passwd for svnowner and change /sbin/nologin to /bin/sh
  • Use the URI syntax to access your created repository (i.e. the test repository created in the example)
svn+ssh://svnowner@server_name/volume1/svn/test

in my case, the ssh port is not 22. there are svn client specific ways to handle this. with tortisesvn (what I use), just setup a saved session in putty and replace server_name with the saved session name. specify the port and any other settings you would like.

You can also setup public/private key pairs so you don't have to constantly enter the password for the svnowner.

PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
  • I'm not sure if this is needed, but a light nudge as the root user to the ssh server to re-read the files
ps w | grep sbin/sshd | grep -v grep | awk '{print $1}' | xargs kill -HUP
  • create the directory as the svnowner user
mkdir /var/services/homes/svnowner/.ssh 
chown 700 /var/services/homes/svnowner/.ssh
  • copy the PUBLIC key generated from putty or whatever other program into an authorized keys file
cat > /var/services/homes/svnowner/.ssh/authorized_keys
NOW PASTE THE TEXT OF THE KEY INTO THE WINDOW
NOW TYPE IN CONTROL-D 
chown 644 /var/services/homes/svnowner/.ssh/authorized_keys
  • Finally configure your svn client to access the private key. With putty, you have the option of saving your private key file. Just save it someplace and configure a session to use it (under Connection > SSH > Auth). Also you can configure the username as svnowner. There are a lot of docs out there on configuring ssh (or putty) to use a public/private key pair. google for more information.

That should do it

Install WebSVN

What is WebSVN ?

WebSVN is a php based application which offers a view onto your subversion repositories that's been designed to reflect the Subversion methodology. You can view the log of any file or directory and see a list of all the files changed, added or deleted in any given revision. You can also view the differences between two versions of a file so as to see exactly what was changed in a particular revision.

WebSVN offers many features:

  • Easy to use interface
  • Customisable templating system
  • Colourisation of file listings
  • Blame view
  • Log message searching
  • RSS feed support
  • and more...

For more information check the official website http://www.websvn.info/ and http://websvn.tigris.org/.


How to install WebSVN

First, download the application files here [1] and unzip it in your apache main web directory. At this point we supposed you have created a repository named "test" with a valid configuration in subversion and you have apache with php running.

It is recommended to read the instructions from the included INSTALL.TXT (for websvn 2.3.2, look to 'doc/install.html') but basically you only need to do the following steps to make it works :

  • Create your own config.php file, starting from the default one(/websvn/include/), and edit it. (for websvn 2.3.2, copy 'include/distconfig.php' to the same directory)
  • Add the following line (where /opt/bin is the folder where svn was previously installed):
    $config->setSVNCommandPath('/opt/bin');
  • You should add something like (near line 70)
    $config->addRepository('Some repository','file:///data/svn/somerepository');
    Obviously you can add more repositories here! Add one for test :
    $config->addRepository('Test','file:///volume1/svn/test');
  • Tweak eventually other parameters if you know what you are doing and save the file.
  • Open you php config file (php.ini from /usr/syno/etc/) and make the property safe_mode_execdir of the php.ini file empty
  • Also add the folder, where svn (executable) is installed, to the property open_basedir of the php.ini file. Note: starting with DSM 3.0 open_basedir is instead set in /usr/syno/etc/php/user-setting.ini. Also, setting PHPINI_BASEDIR_DEF is optional. Note: starting with DSM 2.3 the php.ini is overwrited by S97apache-user.sh at boot and everytime you restart http calling S97apache-user.sh script. You should adjust the PHPINI_BASEDIR_DEF from /usr/syno/etc/rc.d/S97apache-user.sh script by adding /opt/bin to it.
  • Restart apache (/usr/syno/etc/rc.d/S97apache-user.sh restart)

Finally you should now have a working WebSVN php application. You can test it here http://yoursite/websvn/.

For any problem or further information check the official website http://www.websvn.info/ and http://websvn.tigris.org/ or synology forum http://forum.synology.com.

Further information

Possible further information and tips from community can be reached at a Synology Forum post over this page. A guide to add HTTP(S) access for your Subversion server can be found here.

Personal tools
Community Resources