#!/bin/bash
TEMPLATE="varnish_template.spec"
SPEC="varnish.spec"
export TS=`date +%Y%m%d`
#svn co http://varnish.projects.linpro.no/svn/trunk/varnish-cache varnish
svn co http://varnish.projects.linpro.no/svn/branches/1.2 varnish

if [ ! -d varnish-`date +%Y%m%d` ] ; then
	mv varnish varnish-`date +%Y%m%d`
else
	mv varnish-`date +%Y%m%d` varnish-`date +%Y%m%d`.bak
	mv varnish varnish-`date +%Y%m%d`
fi

cd varnish-`date +%Y%m%d`
find . -name .svn -exec rm -rf {} \;
find -exec touch {} \;

# create new svn tarball
cd ..
echo -n "creating tar.bz2 ball... "
tar cfj varnish-`date +%Y%m%d`.tar.bz2 varnish-`date +%Y%m%d`
if [ $? == 0 ]; then
	echo "DONE"
else
	echo "FAILED"
fi

# create new svn spec (replace svn date)

cat ${TEMPLATE} | sed -e s/"%CVSDATE%"/"${TS}"/g > ${SPEC}

osc add varnish-`date +%Y%m%d`.tar.bz2
osc ci varnish-`date +%Y%m%d`.tar.bz2 ${SPEC}
