-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon-utils.sh
80 lines (62 loc) · 1.49 KB
/
common-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
RED='\033[0;31m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
CYAN="\033[0;36m"
NC='\033[0m'
error_log() {
printf "${RED}[error - $(date '+%d/%m/%Y %H:%M:%S')] $1${NC}\n"
}
warn_log() {
printf "${YELLOW}[warn - $(date '+%d/%m/%Y %H:%M:%S')] $1${NC}\n"
}
info_log() {
printf "${GREEN}[info - $(date '+%d/%m/%Y %H:%M:%S')] $1${NC}\n"
}
message() {
printf "${CYAN}$1${NC}\n"
}
check_os() {
info_log "Checking OS..."
OS=$(grep -E -i -s 'buntu' /etc/lsb-release)
if [[ -z "$OS" ]]; then
error_log "Only Ubuntu-based systems are supported"
exit 1
fi
info_log "Supported OS found:"
echo "$OS"
}
check_required_software() {
dpkg -s $1 &> /dev/null
RESULT=$?
if [[ $RESULT -eq 0 ]]; then
info_log "'$1' is installed"
else
error_log "'$1' is required but not installed"
exit 1
fi
}
# Check if user is root
check_root_user() {
info_log "Checking user..."
USER_ID=$(id -u)
if [[ $USER_ID -ne 0 ]]; then
error_log "Installer must be executed as root"
exit 1
fi
info_log "User is root"
}
wait_for_pod() {
I=1;
sleep 3
while [ $I -le $4 ]
do
INGRESS_STATUS=$(kubectl get pods -n $1 -l $2 -o jsonpath='{.items[0].status.phase}')
if [[ "$INGRESS_STATUS" == "Running" ]]; then
info_log "$3 is now running"
break
fi
warn_log "[attempt $I of $4] $3 is not running, waiting 3 more seconds..."
sleep 3
I=$((I+1))
done
}