This repository was archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-DevOps-tools
More file actions
executable file
·190 lines (169 loc) · 7.03 KB
/
Update-DevOps-tools
File metadata and controls
executable file
·190 lines (169 loc) · 7.03 KB
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
#!/usr/bin/env bash
if [[ $EUID -ne 0 ]]; then
DEST="${HOME}/bin"
BASHCOMP="${HOME}/.local/share/bash-completion"
mkdir -p "${DEST}"
mkdir -p "${BASHCOMP}"
else
DEST="/usr/local/bin"
BASHCOMP="/etc/bash_completion.d"
fi
echo "Download DevOps tools in ${DEST} directory:"
function Vault {
VAULT_VERSION="$(curl -s https://www.vaultproject.io/downloads | sed 's/<span/\n/g' | grep 'Current Version:' |sed 's/^.*>\([0-9.]*\)<.*$/\1/' | head -n 1)"
if [ -f "${DEST}/consul" ]; then
VAULT_VERSION_INSTALLED=$("${DEST}"/vault version | grep "^Vault" | cut -d'v' -f2 | awk '{print $1}')
fi
if [ "${VAULT_VERSION}" != "${VAULT_VERSION_INSTALLED}" ]; then
echo "Update VAULT in version ${VAULT_VERSION} > ${VAULT_VERSION_INSTALLED}"
curl -s -L -o /tmp/vault.zip "https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip" && unzip -o /tmp/vault.zip -d ${DEST}
else
echo "VAULT already updated in version ${VAULT_VERSION}"
fi
}
function Consul {
CONSUL_VERSION=$(curl -s https://www.consul.io/downloads | sed 's/<span/\n/g' | grep 'Current Version:' |sed 's/^.*>\([0-9.]*\)<.*$/\1/' | head -n 1)
if [ -f "${DEST}/consul" ]; then
CONSUL_VERSION_INSTALLED=$(${DEST}/consul version | grep "^Consul" | cut -d'v' -f2)
fi
if [ "${CONSUL_VERSION}" != "${CONSUL_VERSION_INSTALLED}" ]; then
echo "Update CONSUL in version ${CONSUL_VERSION} > ${CONSUL_VERSION_INSTALLED}"
curl -s -L -o /tmp/consul.zip "https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip" && unzip -o /tmp/consul.zip -d ${DEST}
else
echo "CONSUL already updated in version ${CONSUL_VERSION}"
fi
}
function Stern {
STERN_VERSION=$(curl -s https://api.github.com/repos/wercker/stern/releases/latest | grep '"tag_name":' | cut -d\" -f4)
if [ -f "${DEST}/stern" ]; then
STERN_VERSION_INSTALLED=$(${DEST}/stern --version | cut -d' ' -f3)
fi
if [ "${STERN_VERSION}" != "${STERN_VERSION_INSTALLED}" ]; then
echo "Update STERN in version ${STERN_VERSION} > ${STERN_VERSION_INSTALLED}"
curl -s -L -o ${DEST}/stern "https://github.com/wercker/stern/releases/download/${STERN_VERSION}/stern_linux_amd64" && chmod +x ${DEST}/stern
stern --completion bash > "${BASHCOMP}/stern.bash"
else
echo "STERN already updated in version ${STERN_VERSION}"
fi
}
function Helm {
HELM_VERSION=$(curl -s https://api.github.com/repos/helm/helm/releases/latest | grep '"tag_name":' | cut -d\" -f4)
HELM_MAJ=$(echo "${HELM_VERSION}" | cut -c2)
if [ -f "${DEST}/helm" ]; then
HELM_VERSION_INSTALLED=$("${DEST}"/helm version | grep "version" | cut -d\" -f2)
HELM_MAJ_INSTALLED=$(echo "${HELM_VERSION_INSTALLED}" | cut -c2)
fi
if [ "${HELM_VERSION}" != "${HELM_VERSION_INSTALLED}" ] ; then
if [ "${HELM_MAJ}" -ge "${HELM_MAJ_INSTALLED}" ] ; then
echo "Update HELM in version ${HELM_VERSION} > ${HELM_VERSION_INSTALLED}"
curl -s -L "https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz" | tar zx -C ${DEST} --strip-components=1 linux-amd64/helm
chmod +x ${DEST}/helm
helm completion bash > ${BASHCOMP}/helm.bash
else
echo "HELM already updated in last major version ${HELM_VERSION_INSTALLED}"
fi
else
echo "HELM already updated in version ${HELM_VERSION}"
fi
}
function K9s {
K9S_VERSION=$(curl -s https://api.github.com/repos/derailed/k9s/releases/latest | grep '"tag_name":' | awk -F '"' '{printf("%s",$4)}')
if [ -f "${DEST}/k9s" ]; then
K9S_VERSION_INSTALLED=$(${DEST}/k9s version -s | grep "Version" | awk '{printf("%s",$2)}')
fi
if [ "${K9S_VERSION}" != "${K9S_VERSION_INSTALLED}" ]; then
echo "Update K9S in version ${K9S_VERSION} > ${K9S_VERSION_INSTALLED}"
curl -s -L "https://github.com/derailed/k9s/releases/download/${K9S_VERSION}/k9s_Linux_x86_64.tar.gz" | tar zx -C ${DEST} k9s
else
echo "K9S already updated in version ${K9S_VERSION}"
fi
}
function Kubectl {
KUBECTL_VERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
if [ -f "${DEST}/kubectl" ]; then
KUBECTL_VERSION_INSTALLED=$(${DEST}/kubectl version --client=true 2>/dev/null | cut -d\" -f6)
fi
if [ "${KUBECTL_VERSION}" != "${KUBECTL_VERSION_INSTALLED}" ]; then
echo "Update KUBECTL in version ${KUBECTL_VERSION}"
curl -s -L -o ${DEST}/kubectl "https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl" && chmod +x "${DEST}/kubectl"
kubectl completion bash > "${BASHCOMP}/kubectl.bash"
else
echo "KUBECTL already updated in version ${KUBECTL_VERSION}"
fi
}
function Kubectx {
KUBECTX_VERSION=$(curl -s https://api.github.com/repos/ahmetb/kubectx/releases/latest | grep '"tag_name":' | cut -d\" -f4)
echo "Update KUBECTX in version ${KUBECTX_VERSION}"
curl -s -L "https://github.com/ahmetb/kubectx/releases/download/${KUBECTX_VERSION}/kubectx_${KUBECTX_VERSION}_linux_x86_64.tar.gz" | tar zx -C "${DEST}" kubectx
curl -s -L "https://github.com/ahmetb/kubectx/releases/download/${KUBECTX_VERSION}/kubens_${KUBECTX_VERSION}_linux_x86_64.tar.gz" | tar zx -C "${DEST}" kubens
}
function Rke {
RKE_VERSION=$(curl -s https://api.github.com/repos/rancher/rke/releases/latest | grep '"tag_name":' | cut -d\" -f4)
if [ -f "${DEST}/rke" ]; then
RKE_VERSION_INSTALLED=$(${DEST}/rke version | grep "Running" | cut -d\" -f4 | cut -d' ' -f4)
fi
if [ "${RKE_VERSION}" != "${RKE_VERSION_INSTALLED}" ]; then
echo "Update RKE in version ${RKE_VERSION} > ${RKE_VERSION_INSTALLED}"
curl -s -L -o "${DEST}/rke" "https://github.com/rancher/rke/releases/download/${RKE_VERSION}/rke_linux-amd64" && chmod +x "${DEST}/rke"
else
echo "RKE already updated in version ${RKE_VERSION}"
fi
}
function RancherCLI {
RANCHERCLI_VERSION=$(curl -s https://api.github.com/repos/rancher/cli/releases/latest | grep '"tag_name":' | cut -d\" -f4)
if [ -f "${DEST}/rancher" ]; then
RANCHERCLI_VERSION_INSTALLED=$(${DEST}/rancher --version | cut -d' ' -f3)
fi
if [ "${RANCHERCLI_VERSION}" != "${RANCHERCLI_VERSION_INSTALLED}" ]; then
echo "Update RANCHERCLI in version ${RANCHERCLI_VERSION} > ${RANCHERCLI_VERSION_INSTALLED}"
curl -s -L "https://github.com/rancher/cli/releases/download/${RANCHERCLI_VERSION}/rancher-linux-amd64-${RANCHERCLI_VERSION}.tar.gz" | tar zx ./rancher-"${RANCHERCLI_VERSION}"/rancher -O > ${DEST}/rancher
chmod +x ${DEST}/rancher
else
echo "RANCHERCLI already updated in version ${RANCHERCLI_VERSION}"
fi
}
if [ $# -ne 0 ]; then
for app in "$@"
do
case "${app}" in
"vault")
Vault
;;
"consul")
Consul
;;
"kubectl")
Kubectl
;;
"kubectx")
Kubectx
;;
"helm")
Helm
;;
"stern")
Stern
;;
"k9s")
K9s
;;
"rke")
Rke
;;
"rancher")
RancherCLI
;;
*)
echo "Unknown program!"
esac
done
else
Kubectl
Helm
Stern
K9s
Vault
Consul
Rke
RancherCLI
fi