-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.rc
More file actions
105 lines (87 loc) · 1.61 KB
/
helper.rc
File metadata and controls
105 lines (87 loc) · 1.61 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# shellcheck shell=bash
message() {
local HEADER=""
local FOOTER="\033[0m"
local OPTIONS="-e"
case "$1" in
--section)
HEADER="📦 \033[35m"
;;
--info)
HEADER="🚜 \033[34m"
;;
--warning)
HEADER="📔 \033[33m"
;;
--waiting)
HEADER="\r📔 \033[33m"
OPTIONS="-en"
;;
--success)
HEADER="🍺 \033[32m"
;;
--error)
HEADER="💊 \033[31m"
;;
--input)
HEADER="🎨 \033[1;37m"
OPTIONS="-en"
;;
*)
HEADER=""
FOOTER=""
;;
esac
echo "$OPTIONS" "$HEADER$2$FOOTER" >&2
}
set_variable() {
eval "VALUE=\"\$$1\""
if [ -n "$VALUE" ]; then
return
fi
if [ "$QUIET" = true ]; then
eval "$1=\"$3\""
else
# shellcheck disable=SC2059
printf "🎨 \033[1;37m$2 (%s): \033[0m" "$3"
read -r VAR
eval "$1=\"${VAR:-$3}\""
fi
}
run_file() {
if [ ! -f "$1" ]; then
return
fi
local TIMES
if [ "$RETRY" = true ]; then
TIMES=0
fi
while ! "$@"; do
if [ "$RETRY" = true ]; then
((TIMES++))
if [ "$RETRY_TIMES" -le 0 ] || [ "$TIMES" -lt "$RETRY_TIMES" ]; then
message --section "Retry $TIMES: $*"
continue
fi
fi
message --error "Failed to run: $*"
exit 1
done
}
run_directory() {
if [ ! -d "$1" ]; then
return
fi
local D
D=$(echo "$1" | sed -E -e 's/\/+$//')
local FILE_PATTERN="$D/*.sh"
local FILE TIMES
for FILE in $FILE_PATTERN; do
run_file "$FILE" "$2"
done
local DIR_PATTERN="$D/*/"
local DIR
for DIR in $DIR_PATTERN; do
run_directory "$DIR" "$2"
done
}