Monday, January 5, 2009

Recursive Bash Function for `svn update`

I work with a pretty fair number of subversion repositories at my employer and am constantly updating each of them manually - which can be both time consuming when remembered at the time I do it, or potentially cause conflicts and be error prone if I forget to do it. So to save myself the trouble of forgetting I have written and crontab'ed this script:
#!/bin/bash
source ~/.bashrc

SVN_ROOT=~/svn

function svnUpOrTraverse {
path=$1
if [[ -d $path ]]
then
upOutput=$(svn up $path)
if [[ $(echo $upOutput | grep 'Skipped') ]]
then
for d in $(find $path -maxdepth 1 | grep -v "$path\$")
do
svnUpOrTraverse $d
done
else
echo "$path Updated":
echo;
fi
fi
}

svnUpOrTraverse $SVN_ROOT

0 comments: