Skip to content

Commit

Permalink
Add clonsetuff
Browse files Browse the repository at this point in the history
  • Loading branch information
wtgodbe committed Oct 26, 2018
1 parent 94355dc commit f5afba4
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
24 changes: 24 additions & 0 deletions CloneStuff.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This script will retry a given command n times (by default we use 5).
# Currently we use this to retry `git clone` during official builds.

param (
[Parameter(Mandatory=$true)][string]$command,
[int]$retries = "5"
)

$done = $false
[int]$retryCount = "0"

do {
Invoke-Expression $command
if ("$LASTEXITCODE" -ne 0) {
$retryCount = $retryCount + 1
} else {
$done = $true
}
if ($retryCount -ge $retries){
Write-Host "Could not complete command after $retries attempts"
$done = $true
}
}
While ($done -eq $false)
51 changes: 51 additions & 0 deletions CloneStuff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# Set default value for __retries
__retries=5
__command=

while :; do
if [ $# -le 0 ]; then
break
fi

lowerI="$(echo $1 | awk '{print tolower($0)}')"
case $lowerI in
command|-command)
if [ -n "$2" ]; then
__command="$2"
shift
else
echo "ERROR: 'command' requires a non-empty option argument"
exit 1
fi
;;
retries|-retries)
if [ -n "$2" ]; then
__retries="$2"
shift
else
echo "ERROR: 'retries' requires a non-empty option argument"
exit 1
fi
;;
*)
esac

shift
done

if [[ -z "$__command"]]
echo "ERROR: Please supply a value for '-command'"
exit 2
fi

__retryCount=0
until $exit_code -eq 0 || [ $__retryCount -ge $__retries ]; do
eval $__command
exit_code=$?
(__retryCount++)
echo "Failed to execute command, retrying"
done

exit $exit_code

0 comments on commit f5afba4

Please sign in to comment.