improve script to use function
diff --git a/releng.control/rsync-retry.sh b/releng.control/rsync-retry.sh
new file mode 100644
index 0000000..aaedb84
--- /dev/null
+++ b/releng.control/rsync-retry.sh
@@ -0,0 +1,58 @@
+function rsync-retry () {
+    if [ -z $1 -o -z $2 ] 
+    then
+        echo "Invalid arguments. Usage is rsync-retry FROMDIR TODIR [verbose] [maxtrys] [pausetime]"
+        return 1
+    fi
+    local FROMDIR=$1
+    local TODIR=$2
+    if [ -z $3 ]
+    then
+       local verboseFlag=false
+    else
+       local verboseFlag=$3
+    fi
+    
+    if [ -z $4 ]
+    then
+       local maxTrys=5
+    else
+       local maxTrys=$4
+    fi
+
+    if [ -z $5 ]
+    then
+       local nPauseTime=120s
+    else
+       local nPauseTime=$5
+    fi
+
+    local rsyncArgs="aru"
+    if [ $verboseFlag ] 
+    then
+        rsyncArgs="${rsyncArgs}v"
+    fi
+     
+    exitCode=-1
+    nTrys=0
+    
+    until [ $exitCode == 0 ]
+    do  
+     ${REMOTE_SSH_COMMAND} rsync -${rsyncArgs} ${FROMDIR} ${TODIR}
+     exitCode=$?
+     if [ $exitCode != 0 ]
+     then
+         nTrys=$(($nTrys + 1))
+         if [ $verboseFlag ] ; then
+             echo "rsync failed with $exitCode. Retrying $nTrys times after $nPauseTime."
+             if [ $nTrys -gt $maxTrys ] ; then
+                 echo "Number of re-trys exceeded. rsync exit code: $exitCode"
+                 return $exitCode
+             fi
+         sleep $nPauseTime
+         fi
+     fi 
+    done
+    
+    return $exitCode
+}