#!/bin/bash
#
# repopuller - use svnsync to grab a copy of a Subversion 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 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
else
    echo "repopuller: $operand does not look like a Subversion repository."
    exit 1
fi

# end
