-
Notifications
You must be signed in to change notification settings - Fork 0
/
_lib.sh
executable file
·97 lines (71 loc) · 1.58 KB
/
_lib.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
#!/bin/bash
LIBSOURCED="TRUE"
# Reset
NC="\033[0m" # Text Reset
# Regular Colors
RED="\033[0;31m"
REDF="\033[1;31m"
REDB="\033[1;41m"
GREEN="\033[0;32m"
CYAN="\033[0;36m"
BCYAN="\033[1;36m"
BORANGE="\e[38;5;208m"
function echo_fatal() {
local prompt_text=$1
echo -e "${REDB}$prompt_text${NC}"
}
function echo_error() {
local prompt_text=$1
echo -e "${REDF}Error:${NC} ${RED}$prompt_text${NC}"
}
function echo_success() {
local prompt_text=$1
echo -e "${GREEN}$prompt_text${NC}"
}
function echo_warning() {
local prompt_text=$1
echo -e "${YELLOW}$prompt_text${NC}"
}
function echo_info() {
local prompt_text=$1
echo -e "${CYAN}$prompt_text${NC}"
}
function ask_with_yes_no() {
local question="${1}"
read -r -p "$(echo -e "${BORANGE}${question}${NC} (y/n)" ) " -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
return 0 # Yes
else
return 1 # No
fi
}
function check_params() {
local do_exit=false
for var in "$@"; do
if [[ -z "${!var}" ]]; then
echo_error "$var is required but not configured"
local do_exit=true
fi
done
[[ ${do_exit} == false ]] || exit 2
}
function check_secret() {
local do_exit=false
for var in "$@"; do
if [[ -z "${!var}" ]]; then
echo_error "$var is required but not configured! Please use *.sec file"
local do_exit=true
fi
done
[[ ${do_exit} == false ]] || exit 2
}
function write_line_if_not_exists () {
local line=$1
local file=$2
if grep -qxF "$line" "$file" ; then
: # echo "$line exists in $file"
else
echo "$line" >> "$file"
fi
}