oops
[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     cd $where
7     while true; do
8         [ -d .svn ] && { echo svn ; return ; }
9         [ -d .git ] && { echo git ; return ; }
10         [ "$(pwd -P)" == "/" ] && { echo none ; return ; }
11         cd ..
12     done
13 }
14
15 # idem but runs in a subshell to protect cwd
16 function svn_or_git () { ( _svn_or_git "$@" ; ) }
17
18 ####################
19 # without an argument, use the place where the command is stored
20 if [[ -z "$@" ]] ; then
21     DIRNAME=$(dirname $0)
22     DIRNAME=$(cd $DIRNAME; pwd -P)
23 else
24     DIRNAME="$1" ; shift
25 fi
26
27 ##########
28 cd $DIRNAME
29 case $(_svn_or_git) in 
30     svn) (date ; svn update ) >& .auto-update.log ;;
31     git) (date ; git pull ) >& .auto-update.log ;;
32     *) echo 'only svn and git are supported' >& .auto-update.log ;;
33 esac