1#!/bin/bash 2# Copyright (c) Meta Platforms, Inc. and affiliates. 3# 4# This source code is licensed under the MIT license found in the 5# LICENSE file in the root directory of this source tree. 6 7set -ex 8 9# Source: https://gist.github.com/sj26/88e1c6584397bb7c13bd11108a579746 10# Modified to 1) address lint errors and 2) output to stderr. 11# 12# Retry a command up to a specific numer of times until it exits successfully, 13# with exponential back off. 14# 15# $ retry 5 echo Hello 16# Hello 17# 18# $ retry 5 false 19# Retry 1/5 exited 1, retrying in 1 seconds... 20# Retry 2/5 exited 1, retrying in 2 seconds... 21# Retry 3/5 exited 1, retrying in 4 seconds... 22# Retry 4/5 exited 1, retrying in 8 seconds... 23# Retry 5/5 exited 1, no more retries left. 24# 25function retry { 26 local retries=$1 27 shift 28 29 local count=0 30 until "$@"; do 31 exit=$? 32 wait=$((2 ** count)) 33 count=$((count + 1)) 34 if [ $count -lt "$retries" ]; then 35 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..." >&2 36 sleep $wait 37 else 38 echo "Retry $count/$retries exited $exit, no more retries left." >&2 39 return $exit 40 fi 41 done 42 return 0 43} 44 45CURRENT_DIR=$(pwd) 46export KOTLIN_HOME="$CURRENT_DIR/third-party/kotlin" 47retry 3 scripts/download-kotlin-compiler-with-buck.sh 48 49retry 3 buck fetch ReactAndroid/src/test/java/com/facebook/react/modules 50retry 3 buck fetch ReactAndroid/src/main/java/com/facebook/react 51retry 3 buck fetch ReactAndroid/src/main/java/com/facebook/react/shell 52retry 3 buck fetch ReactAndroid/src/test/... 53retry 3 buck fetch ReactAndroid/src/androidTest/... 54