forked from fl4p/batmon-ha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinclude.sh
187 lines (161 loc) · 3.96 KB
/
include.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# Common bash functions shared by the build scripts.
export bin_dir="$(pwd)/.bin"
export container_iid="container.iid"
# Color initialization guard due to the use of read-only bash variables.
export _colors_initialized=0
function _do_color_setup() {
# Bash color includes from
# https://raw.githubusercontent.com/WolfSoftware/bash-colour-include/master/src/bash-colour-include.sh
fgBlack=''
fgRed=''
fgGreen=''
fgYellow=''
fgBlue=''
fgMagenta=''
fgCyan=''
fgWhite=''
bgBlack=''
bgRed=''
bgGreen=''
bgYellow=''
bgBlue=''
bgMagenta=''
bgCyan=''
bgWhite=''
screen_width=''
bold=''
dim=''
underline=''
stop_underline=''
reverse=''
cinvis=''
cnorm=''
bell=''
reset=''
cls=''
if test -t 1; then
# see if it supports colors...
ncolors=$(tput colors)
if test -n "${ncolors}" && test "${ncolors}" -ge 8; then
fgBlack=$(tput setaf 0)
fgRed=$(tput setaf 1)
fgGreen=$(tput setaf 2)
fgYellow=$(tput setaf 3)
fgBlue=$(tput setaf 4)
fgMagenta=$(tput setaf 5)
fgCyan=$(tput setaf 6)
fgWhite=$(tput setaf 7)
bgBlack=$(tput setab 0)
bgRed=$(tput setab 1)
bgGreen=$(tput setab 2)
bgYellow=$(tput setab 3)
bgBlue=$(tput setab 4)
bgMagenta=$(tput setab 5)
bgCyan=$(tput setab 6)
bgWhite=$(tput setab 7)
screen_width=$(tput cols)
bold=$(tput bold)
dim=$(tput dim)
underline=$(tput smul)
stop_underline=$(tput rmul)
reverse=$(tput rev)
cinvis=$(tput civis)
cnorm=$(tput cnorm)
bell=$(tput bel)
reset=$(tput sgr0)
cls=$(tput clear)
fi
fi
declare -x -r fgBlack
declare -x -r fgRed
declare -x -r fgGreen
declare -x -r fgYellow
declare -x -r fgBlue
declare -x -r fgMagenta
declare -x -r fgCyan
declare -x -r fgWhite
declare -x -r bgBlack
declare -x -r bgRed
declare -x -r bgGreen
declare -x -r bgYellow
declare -x -r bgBlue
declare -x -r bgMagenta
declare -x -r bgCyan
declare -x -r bgWhite
declare -x -r screen_width
declare -x -r bold
declare -x -r dim
declare -x -r underline
declare -x -r stop_underline
declare -x -r reverse
declare -x -r cinvis
declare -x -r cnorm
declare -x -r bell
declare -x -r reset
declare -x -r cls
_colors_initialized=1
}
if [ $_colors_initialized != 1 ]; then
_do_color_setup
fi
# Begin our includes.
function log() {
echo "$*" 1>&2
}
function warn() {
log "${fgYellow}WARN: $*${reset}"
}
function error() {
log "${fgRed}ERROR: $*${reset}"
}
function success() {
log "${fgGreen}SUCCESS: $*${reset}"
exit 0
}
function fatal() {
local retcode="$1"
shift
log "${fgRed}FATAL: $*${reset}"
exit "$retcode"
}
# check_requirements and alias the input list to the exact paths.
function check_requirements() {
# Alias all commands to their full paths.
local cmd
for p in "$@" ; do
# Assign
cmd="$(command -v "${p}")"
alias "$p=${cmd}"
# Check the command works.
if [ ! -x "${cmd}" ]; then
fatal 1 "Could not find required program (please install it): $p ($cmd)"
fi
done
return 0
}
function is_ci() {
if [ -n "${CODEBUILD_BUILD_ID+}" ]; then
# AWS Codebuild CI
return 0
fi
if [ -n "${CI}" ]; then
# Generic CI
return 0
fi
return 1
}
function parse_filelist() {
export py_files=()
for arg in "$@"; do
case "$arg" in
*.py)
py_files+=( "$arg" )
;;
esac
done
}
function find_pyfiles() {
mapfile -d $'\0' py_files < <(find . -path ./.venv -prune -o -name '*.py' -print0)
export py_files
}