Skip to content
Snippets Groups Projects
Commit 3344549d authored by david_williams's avatar david_williams
Browse files

improve script to use function

parent 8eb36c5e
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,8 @@ function usage() { ...@@ -8,6 +8,8 @@ function usage() {
printf "\n\t\t%s\n\n" "where <projectname> is wtp-R2.0-M, wtp-R3.0-I, wtp-R3.0-N, etc." >&2 printf "\n\t\t%s\n\n" "where <projectname> is wtp-R2.0-M, wtp-R3.0-I, wtp-R3.0-N, etc." >&2
} }
source rsync-retry.sh
verboseFlag= verboseFlag=
deleteOld= deleteOld=
doCopy= doCopy=
...@@ -150,34 +152,12 @@ printf "\t\t%s\n\n" "using the build from ${FROMDIR}" ...@@ -150,34 +152,12 @@ printf "\t\t%s\n\n" "using the build from ${FROMDIR}"
if [ $doCopy ] if [ $doCopy ]
then then
rsyncArgs="aru" rsync-retry ${FROMDIR} ${TODIR} $verboseFlag
if [ $verboseFlag ] exitCode=$?
then if [ $exitCode -ne 0 ]
rsyncArgs="${rsyncArgs}v" then
fi exit $exitCode
fi
maxTrys=5
exitCode=-1
nTrys=0
nPauseTime=120s
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"
exit $exitCode
fi
sleep $nPauseTime
fi
fi
done
fromString="webtools/committers" fromString="webtools/committers"
toString="webtools/downloads" toString="webtools/downloads"
......
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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment