-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-kubectl.sh
More file actions
executable file
·54 lines (42 loc) · 1.14 KB
/
get-kubectl.sh
File metadata and controls
executable file
·54 lines (42 loc) · 1.14 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
#######################
#
# Author: J-dar Siegfred Rodriguez
# Created: Aug. 21, 2021
#
# Used to download and verify kubectl
# Usage: get-kubectl.sh <KUBECTL-VERSION> <OUTPUT-DIRECTORY>
#
####################
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ]
then
echo "Usage: get-kubectl.sh <KUBECTL-VERSION> <OUTPUT-DIRECTORY>"
exit 1
fi
temp_dir=$(mktemp -d)
download_kubectl() {
local version=$1
echo "Downloading kubectl $version"
wget https://dl.k8s.io/release/v$version/bin/linux/amd64/kubectl -q --show-progress -P $temp_dir
}
validate_kubectl() {
local version=$1
echo "Verifying sha256sum..."
local sum=$(curl -sL https://dl.k8s.io/v$version/bin/linux/amd64/kubectl.sha256)
if ! $(echo "$sum $temp_dir/kubectl" | sha256sum --check --status)
then
echo "Sha256sum failed, file invalid or corrupt."
exit 1
fi
}
download_kubectl $1
validate_kubectl $1
tmp_file="${temp_dir}/kubectl"
target_dir="$2/$1"
mkdir "${target_dir}"
mv "${tmp_file}" "${target_dir}/"
rm -R ${temp_dir}
echo "Executing chmod +x on kubectl"
sudo chmod +x "${target_dir}/kubectl"
echo "Finished"
exit 0