#! /bin/sh -e
#
# The script to create empty issue database.
#
# Copyright (c) 2006-2007 The DITrack Project, www.ditrack.org.
#
# $Id: dt-createdb 1079 2007-01-14 02:37:53Z vss $
# $HeadURL: https://127.0.0.1/ditrack/src/tags/0.5/dt-createdb $
#
# Redistribution and use in source and binary forms, with or without 
# modification, are permitted provided that the following conditions are met:
#
#  * Redistributions of source code must retain the above copyright notice, 
# this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright notice, 
# this list of conditions and the following disclaimer in the documentation 
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
# POSSIBILITY OF SUCH DAMAGE.
#

if [ $# -ne 3 ]; then
	echo "Syntax:"
	echo "	$0 <repository-url> <issue-db-dir> <local-wc>"
	echo 
	echo "The script non-recursively checks out <repository-url> into <local-wc> (which"
	echo "should not exist), creates <issue-db-dir> there and schedules it for addition."
	echo
	exit 1
fi

REPO=$1
DBDIR=$2
LOCALWC=$3

if [ -e $LOCALWC ]; then
	echo "'$LOCALWC' already exists"
	exit 1
fi

svn co -Nq $REPO $LOCALWC

DBDIR="$LOCALWC/$DBDIR"

mkdir $DBDIR
mkdir $DBDIR/data
mkdir $DBDIR/etc
mkdir $DBDIR/meta

cat > $DBDIR/README.txt	<<EOM
This is an issue database maintained by DITrack.
Check out http://www.ditrack.org/ for more information.
EOM

cat > $DBDIR/etc/categories <<EOM
Category: sample
Default-owner: sample-user
Version-set: sample-versions-set
EOM

cat > $DBDIR/etc/filters <<EOM
sample-filter: Status=open,Owned-by=sample-user
EOM

cat > $DBDIR/etc/users <<EOM
sample-user
EOM

cat > $DBDIR/etc/versions <<EOM
sample-versions-set: 0.1 0.2 / 0.3 0.4 / 0.5 0.6
EOM

echo "1" > $DBDIR/meta/next-id

svn add -q $DBDIR

svn ps ditrack:format 2 $DBDIR

echo
echo "Empty issue database created at:"
echo "'$DBDIR'"
echo
echo "Now you should probably type something like:"
echo
echo "svn commit $DBDIR"
echo
