build on f29
[infrastructure.git] / scripts / auto-update.sh
1 #!/bin/bash
2 # performs svn update in this command's directory
3
4 function _svn_or_git () {
5     where="$1"; [ -z "$where" ] && where="."
6     pushd $where >& /dev/null
7     cd $(pwd -P)
8     while true; do
9         [ -d .svn ] && { popd >& /dev/null; echo svn ; return ; }
10         [ -d .git ] && { popd >& /dev/null; echo git ; return ; }
11         [ "$(pwd -P)" == "/" ] && { popd >& /dev/null; echo none ; return ; }
12         cd ..
13     done
14 }
15
16 # idem but runs in a subshell to protect cwd
17 function svn_or_git () { ( _svn_or_git "$@" ; ) }
18
19 ####################
20 # without an argument, use the place where the command is stored
21 if [[ -z "$@" ]] ; then
22     DIRNAME=$(dirname $0)
23     DIRNAME=$(cd $DIRNAME; pwd -P)
24 else
25     DIRNAME="$1" ; shift
26 fi
27
28 ##########
29 cd $DIRNAME
30 case $(_svn_or_git) in 
31     svn) (date ; svn update ) >& .auto-update.log ;;
32     git) (date ; git pull ) >& .auto-update.log ;;
33     *) echo 'only svn and git are supported' >& .auto-update.log ;;
34 esac