X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=scripts%2Fauto-update.sh;h=899f919c5cbc1a6b745b5da23b48ec8ee4203257;hb=b4194e90d40b456cc4e7fc32e4246b57b5c60467;hp=92bf96a5c87957db2ae7daee9b1335bd9931ba47;hpb=2f85ea30133d1026fc754f760fa1cd60d161c21b;p=infrastructure.git diff --git a/scripts/auto-update.sh b/scripts/auto-update.sh index 92bf96a..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 +} +# 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 -[ -d .svn ] && (date ; svn update ) &> .auto-update.log -[ -d .git ] && (date ; git pull ) &> .auto-update.log +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