X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=scripts%2Fauto-update.sh;h=899f919c5cbc1a6b745b5da23b48ec8ee4203257;hb=ffb585a5ea7bcf4c102c1b270ef43ddf60779af5;hp=64d4211811a35b6a69c25f545b0256dd3e54a254;hpb=46511b99bd80239a59863c3b7c80ff1f7b6d7705;p=infrastructure.git diff --git a/scripts/auto-update.sh b/scripts/auto-update.sh index 64d4211..899f919 100755 --- a/scripts/auto-update.sh +++ b/scripts/auto-update.sh @@ -1,8 +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 -(date ; svn update ) &> .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