#!/usr/bin/env bash
SVN_DOMAIN="https://svn.mydomain.com"
SVN_REPO="FOODLES"
SVN_URL="${SVN_DOMAIN}/${SVN_REPO}"

while getopts "r:b:h" opt
do
    case $opt in
        r) echo -e "Checking out revision:\t $OPTARG";
           REVISION="$OPTARG"
           ;;
        b) echo -e "Checking out basedir:\t $OPTARG";
           BRANCH="$OPTARG"
           # If I can't list the branch, exit.
           if [ ! `svn ls  ${SVN_URL}/branches 2> /dev/null |grep ${BRANCH}` ]
           then
             echo "Error: Branch ${BRANCH} not found. Exiting."
             exit
           fi
           ;;
        h) echo -e "HELP: How to run this script"
           echo -e "The script can take 2 options."
           echo -e "-r<revision> will build that revision. Default = HEAD revision."
           echo -e "-b<branch name>  will build that branch.  Defailt = trunk. DO NOT INCLUDE /branch/ in the name."
           exit
           ;;
   esac
done
shift $(($OPTIND -1 ))

if [ -z "${REVISION}" ] ;then
    REVISION="HEAD"
fi

if [ -z "${BRANCH}" ] ; then
    BRANCH="trunk"
fi

exit
