X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=scripts%2Fauto-update.sh;h=899f919c5cbc1a6b745b5da23b48ec8ee4203257;hb=b4194e90d40b456cc4e7fc32e4246b57b5c60467;hp=dc7ae47d50df8e60b2336742e9a183a4558b7821;hpb=3ef46d30d35e70e020650c48ec636289325e90d0;p=infrastructure.git diff --git a/scripts/auto-update.sh b/scripts/auto-update.sh index dc7ae47..899f919 100755 --- a/scripts/auto-update.sh +++ b/scripts/auto-update.sh @@ -1,9 +1,34 @@ #!/bin/bash # performs svn update in this command's directory -DIRNAME=$(dirname $0) -DIRNAME=$(cd $DIRNAME; pwd -P) +function _svn_or_git () { + where="$1"; [ -z "$where" ] && where="." + pushd $where >& /dev/null + cd $(pwd -P) + while true; do + [ -d .svn ] && { popd >& /dev/null; echo svn ; return ; } + [ -d .git ] && { popd >& /dev/null; echo git ; return ; } + [ "$(pwd -P)" == "/" ] && { popd >& /dev/null; echo none ; return ; } + cd .. + done +} -cd $DIRNAME -(date ; svn update ) &> .auto-update.log +# idem but runs in a subshell to protect cwd +function svn_or_git () { ( _svn_or_git "$@" ; ) } + +#################### +# without an argument, use the place where the command is stored +if [[ -z "$@" ]] ; then + DIRNAME=$(dirname $0) + DIRNAME=$(cd $DIRNAME; pwd -P) +else + DIRNAME="$1" ; shift +fi +########## +cd $DIRNAME +case $(_svn_or_git) in + svn) (date ; svn update ) >& .auto-update.log ;; + git) (date ; git pull ) >& .auto-update.log ;; + *) echo 'only svn and git are supported' >& .auto-update.log ;; +esac