-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.sh
executable file
·83 lines (70 loc) · 1.44 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
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
#!/usr/bin/env bash
# @see - https://stackoverflow.com/a/5947802
NC='\033[0m'
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LIGHT_GRAY='\033[0;37m'
DARK_GRAY='\033[1;30m'
LIGHT_RED='\033[1;31m'
LIGHT_GREEN='\033[1;32m'
YELLOW='\033[1;33m'
LIGHT_BLUE='\033[1;34m'
LIGHT_PURPLE='\033[1;35m'
LIGHT_CYAN='\033[1;36m'
WHITE='\033[1;37m'
function print_info () {
echo -e "${YELLOW}$1${NC}"
}
function print_success () {
echo -e "${GREEN}$1${NC}"
}
function print_failure () {
echo -e "${RED}$1${NC}"
}
function error_check_return () {
local error_code=$?
local successMessage="$1"
local failureMessage="$2"
if [ "$error_code" != "0" ]; then
print_failure "$failureMessage"
return "$error_code"
fi
print_success "$successMessage"
}
function error_check_exit () {
local error_code=$?
local successMessage="$1"
local failureMessage="$2"
if [ "$error_code" != "0" ]; then
print_failure "$failureMessage"
exit "$error_code"
fi
print_success "$successMessage"
}
# Is the command available to be executed?
#
# @param $1 command
# The command
function dependencyExists () {
if [[ $(which "$1" | wc -l) = 1 ]]; then
return 0
else
return 1
fi
}
# Does the file exist?
#
# @param $1 pathToFile
# The path to the file to check the existence of
function fileExists () {
if [[ -f "$1" ]]; then
return 0
else
return 1
fi
}