Wednesday, August 8, 2012

Packaging Csync2 in RPM on CentOS 6.X

This is a how to package in RPM format, the Csync2 synchronization tool on CentOS 6.x.

Steps

  1. Append RPM Forge repository by creating the file /etc/yum.repos.d/rpmforge.repo with the following content:
  2. $ sudo dd of=/etc/yum.repos.d/rpmforge.repo << EOT
    [rpmforge]
    name=CentOS-$releasever - Rpmforge
    baseurl=http://apt.sw.be/redhat/el6/en/$basearch/rpmforge
    gpgcheck=0
    enabled=1
    EOT
    
    
  3. Install building dependencies:
  4. $ sudo yum -y groupinstall "Development Tools"
    $ sudo yum -y install openssl-devel 
    $ sudo yum -y install librsync librsync-devel
    $ sudo yum install gnutls openssl libtasn1 gnutls-devel
    
    
  5. Create a temporal cache and define a downloader command:
  6. $ mkdir -p /tmp/cache
    
    #/** 
    # * Downloads a file to the cache if doesn't exists
    # *
    # * @param $1 the file to download
    # * @param $2 the url where the file is located
    # */
    $ get() {
     [ -f /tmp/cache/$1 ] || wget -t inf -w 5 -c $2/$1 -O /tmp/cache/$1
    }
    
    
  7. Download latest csync2 tarball with sources:
  8. $ lastver=1.34
    $ cs=csync2-$lastver.tar.gz
    $ get $cs http://oss.linbit.com/csync2/$cs 
    
    
  9. Download an sqlite compatible version:
  10. $ sqver=2.8.16
    $ sq=sqlite-$sqver.tar.gz
    get $sq http://pkgs.fedoraproject.org/repo/pkgs/sqlite/$sq/9c79b461ff30240a6f9d70dd67f8faea/$sq
    
    
  11. Create a clean RPM build environment:
  12. $ rm -rf ~/rpmbuild ~/.rpmmacros
    $ mkdir -p ~/rpmbuild/{BUILD,RPMS,S{OURCE,PEC,RPM}S}
    $ cat > ~/.rpmmacros <<< "%_topdir $HOME/rpmbuild"
    
    
  13. Copy the sources tar balls to SOURCES and BUILD:
  14. $ cd ~/rpmbuild
    $ cp /tmp/cache/$cs SOURCES/
    $ cp /tmp/cache/$sq BUILD/
    
    
  15. Extract the csync2.spec archive from tar ball and modify it to user sqlite sources and include some missing files into the final RPM:
  16. $ cd SPECS
    $ tar --strip-components=1 -x csync2-$lastver/csync2.spec -vzf ../SOURCES/$cs
    $ sed -i \
      -e 's/^%changelog/%files\n%defattr(-,root,root,-)\n\/usr\/sbin\/csync2-compare\n\/etc\/csync2.cfg\n\/etc\/xinetd.d\/csync2\n\/usr\/sbin\/csync2\n\/usr\/share\/man\/man1\/csync2.1.gz\n\n&/' \
      -e 's/\(^%configure\)/\1  --with-libsqlite-source=..\/sqlite-2.8.16.tar.gz  --disable-gnutls/' csync2.spec
    $ cd ..
    
    
  17. Build and install the csync2 RPM packages:
  18. $ rpmbuild -bb SPECS/csync2.spec
    $ sudo rpm -ivh RPMS/x86_64/csync2-$lastver-1.x86_64.rpm
    
    

Enjoy it!