-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·133 lines (123 loc) · 3.18 KB
/
test.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/sh
# set HELM_BIN using Helm, or default to 'helm' if empty
HELM_BIN="${HELM_BIN:-helm}"
PROGNAME="$(basename $0 .sh)"
TIMEOUT=5
display_help() {
echo "Usage: helm $PROGNAME [option...]" >&2
# echo
echo " -t change default timeout, in seconds (default 5)"
# echo " -d, --display Set on which display to host on "
echo
# echo some stuff here for the -a or --add-options
exit 0
}
# TRAPS!
trap 'printf "\n----\n%s\n----\n" "ABORTING!"; exit 1' INT HUP
handle_error(){
# red=`tput setaf 1`
# green=`tput setaf 2`
# reset=`tput sgr0`
tput setaf 1; printf "ERROR: " && tput sgr0 ; printf "%s\n" "$1" >&2
exit 1
}
# check if var is integer
is_integer(){
case "${1#[+-]}" in
(*[!0123456789]*) return 1 ;;
('') return 1 ;;
(*) return 0 ;;
esac
}
# --
while :
do
case "$1" in
-t | --[tT]imeout)
if [ $# -ne 0 ]; then
if is_integer "$2"; then
echo "setting timeout to: $2" && TIMEOUT="$2"
else
echo "Please use a NUMBER for timeout! (e.g, '4' for 4 secs)"
exit 1
fi
fi
shift 2
;;
-[hH] | --[hH]elp)
display_help
exit 0
;;
--)
shift
break
;;
-*)
echo "Illegal option!"
display_help
exit 1
;;
*)
break
;;
esac
done
# --
# more POSIXy(?) getopts, no "--" for now
#while getopts ":[hH]t:" option; do
# case "$option" in
# t) if is_integer "$OPTARG"; then
# echo "Setting timeout to: $OPTARG" && TIMEOUT="$OPTARG"
# else
# echo "Please use a NUMBER for timeout! (e.g, '4' for 4 secs)"
# exit 1
# fi
# ;;
# # v) echo "Verbose mode on" && _V=1
# # ;;
# [Hh]) display_help
# exit 0
# ;;
# \?) echo "Illegal option."
# display_help
# exit 1
# ;;
# esac
#done
## Get rid of the options that were processed
#shift $((OPTIND -1))
fun(){
if [ -n "$1" ] ; then
IN="$1"
else
read IN
fi
[ -z "$IN" ] && return 0
echo "ERROR: $IN"
}
color_print(){
red='tput setaf 1'
green='tput setaf 2'
reset='tput sgr0'
$green ; printf "%s\n" "$1"
$reset
}
(timeout 3 echo hello 2>&1 >&3 3>&- | fun >&2 3>&-) 3>&1
color_print balalalallalal
#timeout 0 echo hello > >(tee -a stdout.log) 2> >(tee -a stderr.log >&2)
timeout "$TIMEOUT" kubectl cluster-info > /dev/null 2>&1
test ${?} -eq 0 || handle_error "the server might be offline"
namespaces=$(kubectl get namespaces -o custom-columns=:.metadata.name)
for namespace in $namespaces
do
echo "Namespace: $namespace"
echo "--------"
helm_charts="$($HELM_BIN list -a -n ${namespace} --short)"
if [ -z "$helm_charts" ]; then
echo "Namespace is empty!"
else
for chart in $helm_charts ; do
"$HELM_BIN" delete -n "${namespace}" "$chart"
done
fi
done