build on f29
[infrastructure.git] / scripts / auto-update.sh
index 64d4211..899f919 100755 (executable)
@@ -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