-
Notifications
You must be signed in to change notification settings - Fork 0
/
common-functions.sh
58 lines (49 loc) · 983 Bytes
/
common-functions.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
export RED='\033[1;31m'
export WHITE='\033[1;37m'
export YELLOW='\033[1;33m'
export NC='\033[0m'
export ERROR="${RED}[error]${NC}"
export WARNING="${YELLOW}[warning]${NC}"
export INFO="${WHITE}[info]${NC}"
function error() {
echo -e "${ERROR} $@"
}
function warning() {
echo -e "${WARNING} $@"
}
function information() {
echo -e "${INFO} $@"
}
# $1 = NAME, $2 = EXECUTABLE
function checkExecutable() {
if [ "$2" == "" ] ; then
error "$1 variable for executable not set."
exit 1
fi
if [ ! -x "$2" ] ; then
error "$1 not found at: $2"
exit 1
fi
}
# $1 = NAME, $2 = FILE
function checkFile() {
if [ "$2" == "" ] ; then
error "$1 variable for file not set."
exit 1
fi
if [ ! -f "$2" ] ; then
error "$1 not found at: $2"
exit 1
fi
}
# $1 = NAME, $2 = FILE
function checkDirectory() {
if [ "$2" == "" ] ; then
error "$1 directory variable not set."
exit 1
fi
if [ ! -d "$2" ] ; then
error "$1: Data directory $2 does not exist."
exit 1
fi
}