Saturday, July 30, 2016

Local SVN


Step 1: Setup Yum Repository

Firstly we need to configure yum repository in our system.
Create a new repo file /etc/yum.repos.d/wandisco-svn.repo and add following
content as per your operating system version.

[WandiscoSVN]
name=Wandisco SVN Repo
baseurl=http://opensource.wandisco.com/centos/$releasever/svn-1.8/RPMS/$basearch/
enabled=1

gpgcheck=0

######################################################################

Step 2: Install Subversion Package

Before installing latest package remove existing subversion packages from system to remove conflict.

# yum remove subversion*
Now install latest available Subversion package using yum command line package manager utility.

# yum clean all

yum install mod_dav_svn subversion

######################################################################

Step 3: Verify Subversion Version

At this stage you have successfully install Subversion client on your system. Lets use following command to verify version of svn client.

[root@localhost /]#  svn --version
svn, version 1.8.16 (r1740329)
   compiled Jul  6 2016, 11:38:59 on x86_64-redhat-linux-gnu

Copyright (C) 2016 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/

The following repository access (RA) modules are available:

* ra_svn : Module for accessing a repository using the svn network protocol.
  - with Cyrus SASL authentication
  - handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
  - handles 'file' scheme
* ra_serf : Module for accessing a repository via WebDAV protocol using serf.
  - using serf 1.3.7
  - handles 'http' scheme
  - handles 'https' scheme

######################################################################

Step 4 : Local SVN Configuration step by step

1) Login to the server on which we need to create the svn.

2) Go to svn directory:
create mkdir -p /usr/local/subversion direcoty
cd /usr/local/subversion
a. Create the folder for which we need to create svn (eg: harry).
To create a svn folder the command is as below.
svnadmin create /usr/local/subversion/harry
chown apache.apache -R harry     -----------------chnage owner permission
chmod 775 -R harry     --------------------------------change folder permission

3)Create svnupload.sh
vim /usr/local/subversion/harry/svnupload.sh


script 1   

#/bin/sh!
home_dir=/usr/local/subversion/harry
svnlook changed /usr/local/subversion/harry >> /usr/local/subversion/harry/test.txt
cat  /usr/local/subversion/harry/test.txt| sed 's/^[A-Z]//g'| sed 's/^  //g' >> /usr/local/subversion/harry/upload.txt
for i in `cat /usr/local/subversion/harry/upload.txt`;do svn export --username 'harry' --password 'harry@123' --no-auth-cache  http://localhost:82/harry/$i /mnt/httpdocs/harry/$i --force;done
for i in `cat /usr/local/subversion/harry/upload.txt`;do chown -R apache:apache /mnt/httpdocs/harry/$i ;done
for i in `cat /usr/local/subversion/harry/upload.txt`;do chmod -R 775 /mnt/httpdocs/harry/$i ;done
> /usr/local/subversion/harry/test.txt
> /usr/local/subversion/harry/upload.txt


script 2

#!/bin/sh
home_dir=/usr/local/subversion/myproject1/
svnlook changed /usr/local/subversion/myproject1 >> /usr/local/subversion/myproject1/test.txt
cat /usr/local/subversion/myproject1/test.txt| sed 's/^[A-Z]//g'| sed 's/^  //g' >> /usr/local/subversion/myproject1/upload.txt
for i in `cat /usr/local/subversion/myproject1/upload.txt`;do svn export --username "svn" --password "Nvs12#4" --no-auth-cache http://localhost/myproject1/$i /var/www/html/$i --force;done
for i in `cat /usr/local/subversion/myproject1/upload.txt`;do chown -R apache:apache /var/www/html/$i ;done
for i in `cat /usr/local/subversion/myproject1/upload.txt`;do chmod -R 775 /var/www/html/$i ;done
cat /usr/local/subversion/myproject1/test.txt |grep D | sed 's/^[A-Z]//g'| sed 's/^  //g' >> /usr/local/subversion/myproject1/delete.txt
for i in `cat /usr/local/subversion/myproject1/delete.txt`;do /bin/rm –rf /var/www/html/$i ;done
> /usr/local/subversion/myproject1/test.txt
> /usr/local/subversion/myproject1/upload.txt
> /usr/local/subversion/myproject1/delete.txt


chown apache.apache /usr/local/subversion/harry/svnupload.sh


4) Create post-commit file
Path : /usr/local/subversion/harry/hooks/
rename post-commit.tmpl to post-commit
chmod +x post-commit

edit post-commit and disable 
vim /usr/local/subversion/harry/hooks/post-commit
#REPOS="$1"
#REV="$2"

#mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf

/bin/sh -x /usr/local/subversion/harry/svnupload.sh ----------------------add this entry

5)Add user in svn

htpasswd -c /var/.htpasswd harry ------------- to create svn user

htpasswd -m /var/.htpasswd john (user name)  -------------------to add user under svn

6) Go to the configuration file of apache. The configuration file may be httpd.conf or it may be
in conf.d/filename.conf.(In this the configuration file is in conf.d directory.)

cd /etc/httpd/conf.d/  -----------------add project name 

vim harry.conf

<VirtualHost *:81>

        ServerName harry.example.com
        DocumentRoot /var/www/html/harry
        <Directory /usr/local/subversion/harry>
          AuthType Basic
          AuthName "Authentication Required"
          AuthUserFile /var/.htpasswd
          Require valid-user
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
#        ErrorLog "|rotatelogs /mnt/log/bhsvn/errorsvn-%Y-%m-%d.log 86400"
#        CustomLog "|rotatelogs /mnt/log/bhsvn/accesssvn-%Y-%m-%d.log 86400" combined

<Location /harry>
       DAV svn
       SVNPath /usr/local/subversion/harry
</Location>

</VirtualHost>

-----------------------------------------------------------------------------------------------------
7)  chmod 775 svnupload.sh    ---change script permission
     chmod +x svnupload.sh    -----prove executive permission

8) cd /var/www/html/ -------------------document root path
mkdir harry
chmod 775 harry
chown apache. harry

 /etc/init.d/httpd reload   ----- reload httpd service

take checkout and try to upload code through local svn

http://localhost:81/harry

2 comments: