-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.shrc
53 lines (45 loc) · 1.01 KB
/
common.shrc
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
# Check passed environment variables names are set
function common.check.var() {
local rc=0
local env_var=''
for env_var in "$@"; do
local env_value="${!env_var}"
if [[ ! -z "${env_value}" ]]; then
echo "[INFO ] '${env_var}' = '${env_value}'"
else
echo "[ERROR] Missing environment variable '${env_var}'" >&2
rc=1
fi
done
return $rc
}
# Check passed command exists
function common.check.bin() {
local rc=0
local command=''
for command in "$@"; do
type -t "${command}" >/dev/null 2>&1 || {
echo "[ERROR] Missing command '${command}'"
rc=1
} >&2
done
return $rc
}
# Check passed files exists and can be executed
function common.check.exe() {
local rc=0
local file=''
for file in "$@"; do
[[ -f "${file}" ]] || {
echo "[ERROR] Missing file '${file}'"
rc=1
continue
} >&2
[[ -x "${file}" ]] || {
echo "[ERROR] Missing execute permission on file '${file}'"
rc=1
continue
} >&2
done
return $rc
}