-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.sh
63 lines (57 loc) · 1.4 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
#!/bin/bash
function logger() {
local TIMESTAMP
TIMESTAMP=$(date +'%Y-%m-%d %H:%M:%S')
case "$1" in
debug)
echo -e "[$TIMESTAMP][\033[36mDEBUG: \033[0m] $2"
;;
info)
echo -e "[$TIMESTAMP][\033[32mINFO: \033[0m] $2"
;;
warn)
echo -e "[$TIMESTAMP][\033[33mWARN: \033[0m] $2"
;;
error)
echo -e "[$TIMESTAMP][\033[31mERROR: \033[0m] $2"
;;
*) ;;
esac
}
function remote_ssh() {
local EMPTY="empty"
local addr=${1-${EMPTY}}
local cmds=""
if [[ ${addr} = "${EMPTY}" ]]; then
exit 1
fi
while [[ $# -gt 1 ]]; do
# comparing with 1 targets to jump the $1
cmd=$2
# if [[ ! "${cmds}" ]]; then
if [[ "${cmds}" = "" ]]; then
cmds="${cmd}"
else
cmds="${cmds}; ${cmd}"
fi
shift
done
logger info "${cmds}"
ssh -tto StrictHostKeyChecking=no "${addr}" "${cmds}; exit"
}
function isMaster() {
if [[ $(ifconfig ens18 | grep 'inet ' | cut -d " " -f 10) == "${MASTER}" ]]; then
return 0
else
return 1
fi
}
function beauty() {
local str len strLen left right
str=${1-}
len=${2-80}
strLen=${#str}
left=$(( (len - strLen) / 2 ))
right=$(( len - strLen - left ))
printf "%s%s%s\n" "$(printf '*%.0s' $(seq 1 $left))" " $str " "$(printf '*%.0s' $(seq 1 $right))"
}