#!/bin/bash
 
# svntar.sh - a script to easily make tar from svn
# by KilledWhale
 
# Base directory where svn repositories are
BASE="/home/users/killedwhale/svn/"
 
# No directory specified so output a list about possible dirs @ base
if [ "$1" == "" ]
then
	ls $BASE
	exit
fi
 
# Try to find the directory
if [ -d "$BASE$1" ]
then
	PAT="file://$BASE$1"
	# Try to get svn info to see that directory is actually a repository
	RET=`svn info $PAT 2> /dev/null`
	if [ $? == 0 ]
	then
		# Grab revision number from svninfo
		REV=`echo $RET | sed -n -e 's/.*Revision: \([0-9]*\).*/\1/p'`
		echo "Exporting, please wait"
		svn export $PAT $1_rev$REV > /dev/null
		echo "Archiving, please wait a bit more"
		tar -czf $1_rev$REV.tar.gz $1_rev$REV/
		echo "Removing temporary files"
		rm -r $1_rev$REV
		echo "Done :)"
	else
		echo "$1 is not valid svn repository"
	fi
else
	echo "Cant't find repository"
fi