-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubectl.sh
executable file
·68 lines (51 loc) · 1.61 KB
/
kubectl.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
#!/bin/bash
NAME="kubectl"
VERSION=${1}
OS_NAME="$(uname | awk '{print tolower($0)}')"
_prepare() {
CONFIG=~/.config/opspresso/latest
mkdir -p ${CONFIG} && touch ${CONFIG}/${NAME}
TMP=/tmp/opspresso/tools
mkdir -p ${TMP}
_brew
}
_brew() {
if [ "${OS_NAME}" == "darwin" ]; then
command -v brew > /dev/null || ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
}
_compare() {
touch ${CONFIG}/${NAME}
NOW=$(cat ${CONFIG}/${NAME} | xargs)
if [ "${VERSION}" != "" ]; then
NEW="${VERSION}"
else
STATUS=$(curl -sLI opspresso.github.io/${NAME}/LATEST | grep "HTTP" | grep "200" | wc -l | xargs)
if [ "${STATUS}" != "0" ]; then
NEW=$(curl -sL opspresso.github.io/${NAME}/LATEST | xargs)
else
NEW="latest"
fi
fi
if [ "${NEW}" != "" ] && [ "${NEW}" != "${NOW}" ]; then
echo "${NOW:-new} >> ${NEW}"
VERSION="${NEW}"
else
VERSION=""
fi
}
echo "================================================================================"
echo "# ${NAME} ${VERSION}..."
_prepare
_compare
if [ "${VERSION}" != "" ]; then
if [ "${OS_NAME}" == "darwin" ]; then
command -v kubectl > /dev/null || brew install kubernetes-cli
else
URL="https://storage.googleapis.com/kubernetes-release/release/${VERSION}/bin/${OS_NAME}/amd64/kubectl"
curl -L -o ${TMP}/${NAME} ${URL}
chmod +x ${TMP}/${NAME} && sudo mv ${TMP}/${NAME} /usr/local/bin/${NAME}
fi
printf "${VERSION}" > ${CONFIG}/${NAME}
fi
kubectl version --client --short