forked from christian-posta/kube-demos
-
Notifications
You must be signed in to change notification settings - Fork 5
/
util.sh
54 lines (46 loc) · 1017 Bytes
/
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
#!/usr/bin/env bash
readonly reset=$(tput sgr0)
readonly green=$(tput bold; tput setaf 2)
readonly yellow=$(tput bold; tput setaf 3)
readonly blue=$(tput bold; tput setaf 6)
function desc() {
maybe_first_prompt
echo "$blue# $@$reset"
prompt
}
function prompt() {
echo -n "$yellow\$ $reset"
}
started=""
function maybe_first_prompt() {
if [ -z "$started" ]; then
prompt
started=true
fi
}
function run() {
maybe_first_prompt
rate=25
if [ -n "$DEMO_RUN_FAST" ]; then
rate=1000
fi
echo "$green$1$reset" | pv -qL $rate
#if [ -n "$DEMO_RUN_FAST" ]; then
# sleep 0.5
#fi
eval "$1"
r=$?
read -d '' -t 0.1 -n 10000 # clear stdin
prompt
if [ -z "$DEMO_AUTO_RUN" ]; then
read -s
fi
return $r
}
function relative() {
for arg; do
echo "$(realpath $(dirname $(which $0)))/$arg" | sed "s|$(realpath $(pwd))|.|"
done
}
SSH_NODE=$(kubectl get nodes | tail -1 | cut -f1 -d' ')
trap "echo" EXIT