#!/bin/sh

# This script is used to download the upstream source for svnclientadapter
# and generate it into an orig source tarball for Debian.

# Common variables used to ease maintenance of this script
SVNCLIENTADAPTER_VERSION="1.10.12"
SVN_REVISION="6002"

USAGE="\n\
This script is used to generate the orig tarball used in building\n\
Debian packages for svnclientadapter-$SVNCLIENTADAPTER_VERSION.\n\
Usage: svnclientadapter-get-orig-source [OPTION]\n\
\n\
 -h, --help                 Display this help message.\n\
 --remove-upstream-source   Remove the upstream source.\n"

while [ "$#" -gt "0" ]
do
    case "$1" in
        --remove-upstream-tarball)
            REMOVE_UPSTREAM_TARBALL=1
            shift
            ;;
        -h|--help|*)
            echo "${USAGE}"
            exit 1
            ;;
    esac
done

make_current_tarball() {
    # Download the source if it's not available in the current directory
    [ -d svnclientadapter-$SVNCLIENTADAPTER_VERSION ] || \
        svn export -r $SVN_REVISION http://subclipse.tigris.org/svn/subclipse/tags/subclipse/1.10.12/svnClientAdapter \
            svnclientadapter-$SVNCLIENTADAPTER_VERSION --username guest --password ""

    rm -rf svnclientadapter-${SVNCLIENTADAPTER_VERSION}/lib
    rm -rf svnclientadapter-${SVNCLIENTADAPTER_VERSION}/test/lib
    tar --exclude-vcs -czf svnclientadapter_${SVNCLIENTADAPTER_VERSION}.orig.tar.gz \
        svnclientadapter-${SVNCLIENTADAPTER_VERSION}/
    jh_repack --upstream-version ${SVNCLIENTADAPTER_VERSION} svnclientadapter_${SVNCLIENTADAPTER_VERSION}.orig.tar.gz

    if [ $REMOVE_UPSTREAM_TARBALL ]; then
        echo -n "Removing upstream source..."
        rm svnclientadapter-$SVNCLIENTADAPTER_VERSION
        echo "done."
    fi
}

make_current_tarball
