#!/bin/bash

# This script will create a tar archive of the source by copying it to 
# tmp and cleaing it.

version=`cat configure | grep " VERSION=" | grep -v PACKAGE_VERSION | sed -e 's/VERSION=//g' | sed -e 's/ //g'`
newsrcdir=/tmp/multisync-${version}
olddir=`pwd`
rm -rf ${newsrcdir}
if (cp -r ${olddir} ${newsrcdir}); then
# Make distclean
cd ${newsrcdir}
make distclean
for dir in ${newsrcdir}/plugins/*; do
   cd ${dir}
   make distclean
done

cd ${newsrcdir}
dirs=`find ${newsrcdir} -type d`
for dir in ${dirs}; do
   rm ${dir}/*~
   rm ${dir}/*.bak
   rm ${dir}/.#*
   rm -rf ${dir}/*.cache
done

dirs=`find ${newsrcdir} -type d -name .libs`
for dir in ${dirs}; do
    rm -rf ${dir}
done
dirs=`find ${newsrcdir} -type d -name .deps`
for dir in ${dirs}; do
    rm -rf ${dir}
done

dirs=`find ${newsrcdir} -type d -name CVS`
for dir in ${dirs}; do
   rm -rf ${dir}
done

cd ${newsrcdir}
rm -rf www
rm -f makesourcetar
rm -rf rpms
rm -rf standards
rm -rf plugins/evolution_plugin/liblinks
rm -rf plugins/evo_address_sync
rm -rf plugins/empty_plugin
rm -rf plugins/remote_sync

cd /tmp/
tar cvfj multisync-${version}.tar.bz2 multisync-${version}
fi
