#!/bin/sh
# svnupdate -- update all my SVN projects (or the current directory)
#
# SUMMARY: If you give this no parameters,
#          it looks first in the current directory, if that's a SVN directory,
#          then it acts like svn update
#          If there are no arguments,
#          and if the current directory isn't a SVN directory, then
#          it updates all of the immediate subdirectories of . that are SVN
#          directories.
#          If you give it arguments, it updates all of the given directories.
#
# AUTHOR:	Gary T. Leavens

[ -n "$echo" ] && set -x

USAGE='svnupdate [dir] ...'

# svndirs -- Print all immediate subdirectories that are SVN directories
# This only prints relative directory names.
svndirs()
{
# no parameters
if test $# -ne 0
then
	echo "$USAGE" >&2
	exit 2
fi

if test -d .svn
then
	echo .
else
    SUBDIRS=`echo */.svn`
    if test "$SUBDIRS" \!= '*/.svn'
    then
	echo "$SUBDIRS" | sed -e 's@/.svn@@g'
    fi
fi
}

# no options allowed
case "$1" in
-*)
	echo "$USAGE" >&2
	exit 2
	;;
esac

if test $# -eq 0
then
    SVNDIRS=`svndirs`
else
    SVNDIRS="$@"
fi

ret=0

case "$SVNDIRS" in 
'*')
	exit $ret
	;;
esac

for d in $SVNDIRS
do
	cd $d && echo $d
	svn update || ret=1
	cd ..
done

exit $ret

