-
Notifications
You must be signed in to change notification settings - Fork 13
/
library.sh
63 lines (49 loc) · 1.55 KB
/
library.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
#
# Please refer to AUTHORS.md for a complete list of Copyright holders.
# Copyright (C) 2016-2023, Dockershelf Developers.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
ANSI_RED="\033[31;1m"
ANSI_GREEN="\033[32;1m"
ANSI_YELLOW="\033[33;1m"
ANSI_RESET="\033[0m"
ANSI_CLEAR="\033[0K"
msginfo(){
echo -e "\n${ANSI_YELLOW}${1}${ANSI_RESET}\n"
}
msgsuccess(){
echo -e "\n${ANSI_GREEN}${1}${ANSI_RESET}\n"
}
msgerror(){
echo -e "\n${ANSI_RED}${1}${ANSI_RESET}\n" >&2
}
cmdretry() {
local RESULT=0
local COUNT=1
while [ ${COUNT} -le 3 ]; do
if [ ${RESULT} -ne 0 ]; then
msgerror "The command \"${@}\" failed. Retrying, ${COUNT} of 3."
fi
set +e
"${@}"
RESULT=${?}
set -e
if [ ${RESULT} -eq 0 ]; then
break
fi
COUNT=$((${COUNT} + 1))
done
if [ ${COUNT} -gt 3 ]; then
msgerror "The command \"${@}\" failed 3 times."
fi
return ${RESULT}
}