-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils.sh
executable file
·33 lines (31 loc) · 1.05 KB
/
utils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env -S bash -e
# To be sourced from other scripts. Tip: use the following lines to source it independently from the PWD,
# provided your script is in the same directory as this one:
# SCRIPTS_DIR="$(readlink -f ${BASH_SOURCE[0]} | xargs dirname)"
# source "$SCRIPTS_DIR/utils.sh"
# Temporary hack, because sourceforge currently rejects connections randomly
function try_multiple_times() {
local ERR
local MAX_TRIES=5
local COUNT=0
while [ $COUNT -lt $MAX_TRIES ]
do
if [ $COUNT -ne 0 ]
then
echo "Retrying \"${@}\" (attempt #$(( COUNT + 1 )))..."
fi
# Execute the command in an IF, just in case "errexit" is enabled
if "${@}"
then
return 0
else
ERR=$?
fi
COUNT=$(( COUNT + 1 ))
done
echo "Failed to execute \"${@}\" after $COUNT attempts. Aborting."
# Simulate a failing command, just in case "errexit" is enabled, to trigger an exit as appropriate
false
# Otherwise return the failing command's status code
return $ERR
}