-
Notifications
You must be signed in to change notification settings - Fork 10
/
getcli.sh
executable file
·195 lines (178 loc) · 4.55 KB
/
getcli.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/sh
set -e
usage() {
echo
echo "Install latest release of banzai-cli. https://github.com/banzaicloud/banzai-cli"
echo
if have curl; then
echo "Usage: curl https://getpipeline.sh/cli | sh [-s -- auto|deb|rpm|brew|tar|go|kubectl]"
elif have wget; then
echo "Usage: wget -O- https://getpipeline.sh/cli | sh [-s -- auto|deb|rpm|brew|tar|go|kubectl]"
else
echo "Usage: $1 [auto|deb|rpm|brew|tar|go|kubectl]"
fi
}
main() {
cmd="$1"
shift
case "$*" in
guess-only)
guess_installer ;;
"")
if have banzai; then
echo "banzai-cli is already installed. Run with 'auto' argument to install/upgrade anyway" >&2
usage $cmd >&2
exit 1
fi
install_`guess_installer` ;;
auto)
install_`guess_installer` ;;
deb)
install_deb ;;
rpm)
install_rpm ;;
tar|tgz|tar.gz)
install_tar ;;
brew)
install_brew ;;
go)
install_go ;;
kubectl) # install kubectl
install_kubectl ;;
*)
usage $cmd >&2
exit 1
esac
}
install_brew() {
brew install banzaicloud/tap/banzai-cli
}
install_rpm() {
if ! have curl; then
echo curl is needed by rpm to install remote packages >&2
exit 1
fi
rpm -i "https://banzaicloud.com/downloads/banzai-cli/latest?format=rpm"
}
install_deb() {
tmp=`tmp`
trap "rm -r $tmp" EXIT
download "https://banzaicloud.com/downloads/banzai-cli/latest?format=deb" $tmp/banzai-cli.deb
SUDO dpkg -i $tmp/banzai-cli.deb
}
install_tar() {
tmp=`tmp`
trap "rm -r $tmp" EXIT
download "https://banzaicloud.com/downloads/banzai-cli/latest?format=tgz&os=`os`" | tar xz -C $tmp
path=`path`
if [ -w $path ]; then
install $tmp/banzai $path
else
SUDO install $tmp/banzai $path
fi
}
install_go() {
go get github.com/banzaicloud/banzai-cli/cmd/banzai
SUDO install -m 755 ${GOPATH:-~/go}/bin/banzai "`path`/banzai"
}
install_kubectl() {
version=`download "https://storage.googleapis.com/kubernetes-release/release/stable.txt" 2>/dev/null`
tmp=`tmp`
trap "rm -r $tmp" EXIT
download "https://storage.googleapis.com/kubernetes-release/release/${version}/bin/`os`/amd64/kubectl" $tmp/kubectl
SUDO install $tmp/kubectl "`path`/kubectl"
}
have() {
type "$@" >/dev/null 2>&1
}
os() {
case "`uname`" in
Darwin) echo darwin ;;
Linux) echo linux ;;
*) echo Unsupported OS. >&2
exit 1
esac
}
if [ "`whoami`" = root ]; then
SUDO() {
"$@"
}
else
SUDO() {
(
set -x
sudo "$@"
)
}
fi
download() {
if have wget; then
wget -O "${2:--}" "$1"
elif have curl; then
curl -L -o "${2:--}" "$1"
else
echo Neither wget, nor curl is available in the system PATH.
exit 1
fi
}
path() {
if echo "$PATH" | tr : '\n' | grep -qs ^/usr/local/bin$; then
echo /usr/local/bin
else
echo /usr/bin
fi
}
tmp() {
if have mktemp; then
dir="`mktemp -d`"
else
dir=/tmp/$USER.$$
mkdir -p $dir
fi
echo $dir
}
guess_installer() {
case "`uname` `uname -m`" in
Darwin*)
if have brew; then
echo brew
else
echo tgz
fi
;;
"Linux x86_64")
[ ! -e /etc/os-release ] || . /etc/os-release
case "$ID" in
centos|rhel|fedora|sles|*suse*)
echo rpm
;;
debian|ubuntu)
echo deb
;;
*)
if have rpm; then
if have dpkg; then
echo "Can't decide between deb and rpm, falling back to tarball" >&2
echo tar
else
echo rpm
fi
else
if have dpkg; then
echo deb
else
echo tar
fi
fi
esac
;;
*)
if have go; then
echo go
else
echo Unsupported operating system. Try installing go to build from source. >&2
exit 1
fi
esac
}
main "$0" "$@"