Life with Subversion on Mandrake 10.1

Last Updated :  Jan 2006

Installing subversion

Installing subverion from source is quite straight forward.  Get the source from http://subversion.tigris.org/project_packages.html .  Follow the instructions from http://www.onlamp.com/pub/a/onlamp/2002/10/31/subversion.html

  • instaleld in /usr/local/subversion-xxx (xxx represents version)
  • created link /usr/local/subversion  -->/usr/local/subverion-xxx
  • added /usr/local/subversion/bin to PATH in /etc/profile
        PATH=$PATH:/usr/local/subverison/bin
        export PATH

  • added
         EDITOR=/bin/vim
    in /etc/profile
  • created symlinks in /usr/local/bin/*  --> /usr/local/subverson/bin/*
    otherwise this causes problems for svn+ssh access

Setting it up

Reference : http://www.linuxfromscratch.org/blfs/view/svn/server/svnserver.html
  • create a user account to run subversion as you don't want to run it as root
        useradd -d /raid/svn -s /bin/false svn
    this also creates a group called 'svn'
  • add other users to svn group
        usermod -G svn svnuser1
  • modify 'svn'  & 'svnserve' binaries to do umask 002  (do it as root)
       # mv /usr/local/subversion/bin/svn /usr/local/subversion/bin/svn.orig
       # mv /usr/local/subversion/bin/svnserve /usr/local/subversion/bin/svnserve.orig
  • create a new file  ' /usr/local/subversion/svn' that looks like this
    #!/bin/sh
    umask 002
    exec /usr/local/subversion/bin/svn.orig "$@"

  • #chmod 0755 /usr/local/subversion/svn
  • create a new file '/usr/local/subversion/svnserve' looks like this
    #!/bin/sh
    umask 002
    exec /usr/local/subversion/bin/svnserve.orig "$@"
     
  • #chmod 0755 /usr/local/subversion/svnserve
  • setup Xinetd (this is wha Mandrake uses instead of inetd)
    • create file /etc/xinet.d/svn
      service svn
          {
                  port                    = 3690
                  socket_type        = stream
                  protocol              = tcp
                  wait                    = no
                  user                    = svn
                  #user                  = root
                  server                 = /usr/local/subversion/bin/svnserve
                  server_args         = -i -r /raid/svn/repos
          }
      notice the server  and -r flag  that specifies the 'root' for svnserve
         
    • add the following lines to /etc/services
      svn             3690/tcp                        # Subversion
      svn             3690/udp                        # Subversion

    • do a '/etc/init.d/xinetd reload' to reload the settings


All set. create a repos

Setting a repository for multiple users with SSH access requires some steps .  Refer this redbook section (at the bottom).

Lets say we are setting up a new repository to work on a new project projectA with users user1 & user2
(all the following commands are executed as root)
  1. create a new group
    # groupadd groupA
  2. create users if they don't have an account already
    # useradd -g groupA user2

    lets say user1 already exists in the system, then add him to this gruop.  One way to do this is by modifying /etc/group file
    groupA:x:514:user2,user1

    setpasswords for users:
    #passwd user2
    (ask the users to change the password as soon as possible)

  3. create repository
    #svnadmin create --fs-type fsfs /raid/svn/repos/projectA  (using file storage rather than Berkeley db)

    #chgrp -R groupA  /raid/svn/repos/projectA (this will make sure all content under the repository belongs to the group)

    #chmod 770  /raid/svn/repos/projectA  (others don't have access to repos, security measure)

    #chmod  -R g+w  /raid/svn/repos/projectA
      (group has read+write permission to repos)

    #chmod  g+s `find /raid/svn/repos/projectA/db -type d`


    (this sets the 'sticky' bit for group for directories in db dir.  This is subtle but important.  Otherwise when a user creates a revision by doing a checkin/commit, the revision will only be accessible to that user, not all in the group.  This way all new revisions/files created will inherit the group of parent directory.
    - don't forget the backward qoutes ` around find command
    - Umask also plays a key role.  The SVN Wrappers with correct umask as noted above solves that problem.)

    verify the above command by issing
    #find db -type d -ls
    10207305    4 drwxrws---   5 root     groupA     4096 Jan  6 15:19 db
    10207308    4 drwxrws---   2 root     groupA     4096 Jan  6 15:19 db/revprops
    10207307    4 drwxrws---   2 root     groupA     4096 Jan  6 15:19 db/revs
    10207309    4 drwxrws---   2 root     groupA     4096 Jan  6 15:19 db/transactions

    Notice the 'stickybit' s.

you need to be on the same machine to do this.  You can not create a repository on a remote machine (TODO : investigate)


import some initial data into it.  This is done so it is easier down the path
from the same machine
$ cd /tmp
$ mkdir 
projectA
$ cd projectA
$ mkdir trunk branches tags
$ svn import -m "initial import" . file://raid/svn/repos/projectA


Adding         branches
Adding         tags
Adding         trunk
Committed revision 1.

   

access the repos

The  default repos has annonymous read access
  • from the same machine:
       $ cd /tmp
       $ svn co file://raid/svn/repos/projectA/trunk 
    projectA
    notice the 'trunk'. 
    Now the 'projectA has the following contents
       $ ls -a projectA
                  ./  ../  brahches/  .svn/  tags/  trunk/
  • from another machine using SVN
      $ svn co svn://svnhost/projectA  projectA
    notice the URL for repository  is not absolute.  It is from the base URL svnserve is being started with (/raid/svn/repos/)
    xinetd --> svnserve (as user svn, specificed in/etc/xinet.d/svn)

  • from another machine using SVN+SSH
       $ svn co svn+ssh://svnhost/raid/svn/repos/projectA  projectA
          svnuser1@svnhost's password : ****
          checkoutd revision 1
    notice the repository URL is absolute!  This is b/c the svnserve is NOT being run by xinetd directly but by sshd
    xinetd --> sshd --> svnserve (as user svnuser)

    WARN 1 : in this case, when I din't have the symlinks for svn binaries in /usr/local/bin I was getting an error
       bash: line 1: svnserve: command not found
       svn: Connection closed unexpectedly

    WARN 2 : if you use the relative repository path like 'svnhost/projectA' the error would be
       svn: No repository found in 'svn+ssh://svnhost/projectA'
    use absolute pathname to dir
    TODO : see how to make SSH launch a custom svnserv server

SVN Access from Eclipse

Eclipse interacts very well with SVN through Subclipse plugin.
  • Installing plugins on Eclipse
    • unzip the zip files into different directories (NOT into eclipse plugins dir!)
    • In Eclipse go to 'Help -> Software Updates -> Find and Install'
    • Choose 'Search for New Features'
    • Select 'New Local Site' button and select a directory where you unzipped Subclipse updater.  Do the same for JavaSVN
    • click FInish.  Eclipse will figure out the updates and install them.  At the end it will ask you to restart eclipse, choose Yes,
    • the plugins are installed
  • NOTE : Once installed go to 'Window --> Preferences --> Team --> SVN' and select JavaSVN as adapter.
  • subversion 1.2 server (this is not significant)

Some more : Updating a website when checking in

Lets say you are working on a web project.  Every time some one checks in you may want to update the development site. This can be done by hook scripts.
  1. create the site dir
    #mkdir /var/www/html/dev
  2. set permissions
    #chgrp groupA /var/www/html/dev
    #chmod g+w+s /var/www/html/dev  (sticky bit is really important)
  3. go into the dir
    $ svn co file:///raid/svn/repos/projectA/trunk/ .
  4. In SVN repository under 'hooks', create a file 'post-commit' (copy from 'post-commit.template').  Make sure it is executable and have this command 
    svn up /var/www/html/dev
Send feedback, comments to hello -at- sujee.net

References

  1. http://www.linuxfromscratch.org/blfs/view/svn/server/svnserver.html
  2. http://subversion.tigris.org/
  3. http://www.onlamp.com/pub/a/onlamp/2002/10/31/subversion.html