-
Notifications
You must be signed in to change notification settings - Fork 4
/
util.sh
executable file
·80 lines (69 loc) · 1.09 KB
/
util.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
#!/bin/bash
#
# Amir Samary - 2018
#
# This script is included on practically all other scripts
#
#
# CONSTANTS
#
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
#
# Utility functions
#
function showError() {
red
printf "\nERROR: $1\n"
nocolor
}
function showMessage() {
green
printf "\n$1\n"
nocolor
}
function printfY() {
yellow
printf "$1"
nocolor
}
function printfR() {
red
printf "$1"
nocolor
}
function printfG() {
green
printf "$1"
nocolor
}
function nocolor() {
printf "${NC}"
}
function yellow() {
printf "${YELLOW}"
}
function red() {
printf "${RED}"
}
function green() {
printf "${GREEN}"
}
# checkError(errorMsg, successMsg)
#
# If last command terminated with an error, prints errorMsg and exits with error returned.
# IF last command did not terminated with an error, prints successMsg.
function checkError() {
if [ ! $? -eq 0 ]
then
printfR "\n$1\n"
exit $?
else
if [ ! -z "$2" ]
then
printfG "\n$2\n"
fi
fi
}