#!/bin/sh
#
# repopuller - use svnsync to grab a copy of a Subversion or CVS repo
#
# Initially requires a single argument, either an SVN URL, e.g
# something like svn://svn.hercules-390.org/hercules or
# svn://svn.debian.org/nut, or a CVS URL, e.g. something like
# cvs://rfk.cvs.sourceforge.net/cvsroot/rfk#robotfindskitten, or the
# name of a local mirror directory created by a previous run.
#
# The first run creates a local mirror of the repository in a directory named
# after the last segment of the URL: that is, the second example
# above would be unpacked into a local directory named 'nut-mirror'.
#
# Later runs can update the local mirror by giving the mirror directory name. 
#
operand=$1

if [ `expr "$operand" : "svn://"` = 6 \
    -o `expr "$operand" : "svn+ssh://"` = 10 \
    -o `expr "$operand" : "https://"` = 8 \
    -o `expr "$operand" : "http://"` = 7 ]
then
    local=`basename $operand`-mirror
    svnadmin create $local
    cat >$local/hooks/pre-revprop-change <<EOF
#!/bin/sh
exit 0;
EOF
    chmod a+x $local/hooks/pre-revprop-change
    svnsync init file://${PWD}/$local $operand
    svnsync synchronize file://${PWD}/$local
elif [ -d "$operand/locks" ]
then
    svnsync synchronize file://${PWD}/$operand
elif [ `expr "$operand" : "cvs://"` = 6 ]
then
    local=`echo basename $operand | sed -e /.*#/s///`-mirror
    mkdir $local
    cvssync -o $local "$operand"
    echo "$operand" >$local/.cvssync
elif [ -d $operand/.cvssync ]
then
    cvssync -o $operand `cat $operand/.cvssync`
else
    echo "repopuller: $operand does not look like a Subversion or CVS repository."
    exit 1
fi

# end
