1
+ #! /bin/sh
2
+
3
+ #
4
+ # This file will be fetched as: curl -L https://git.io/getLatestKubebuilder | sh -
5
+ # so it should be pure bourne shell, not bash (and not reference other scripts)
6
+ #
7
+ # The script fetches the latest kubebuilder release candidate and untars it.
8
+ # It lets users to do curl -L https://git.io//getLatestKubebuilder | KUBEBUILDER_VERSION=1.0.5 sh -
9
+ # for instance to change the version fetched.
10
+
11
+ # Check if the program is installed, otherwise exit
12
+ function command_exists () {
13
+ if ! [ -x " $( command -v $1 ) " ]; then
14
+ echo " Error: $1 program is not installed." >&2
15
+ exit 1
16
+ fi
17
+ }
18
+
19
+ # Determine OS
20
+ OS=" $( uname) "
21
+ case $OS in
22
+ Darwin)
23
+ OSEXT=" darwin"
24
+ ;;
25
+ Linux)
26
+ OSEXT=" linux"
27
+ ;;
28
+ * )
29
+ echo " Only OSX and Linux OS are supported !"
30
+ exit 1
31
+ ;;
32
+ esac
33
+
34
+ HW=$( uname -m)
35
+ case $HW in
36
+ x86_64)
37
+ ARCH=amd64 ;;
38
+ * )
39
+ echo " Only x86_64 machines are supported !"
40
+ exit 1
41
+ ;;
42
+ esac
43
+
44
+ # Check if curl, tar commands/programs exist
45
+ command_exists curl
46
+ command_exists tar
47
+
48
+ if [ " x${KUBEBUILDER_VERSION} " = " x" ] ; then
49
+ KUBEBUILDER_VERSION=$( curl -L -s https://api.github.com/repos/kubernetes-sigs/kubebuilder/releases/latest | \
50
+ grep tag_name | sed " s/ *\" tag_name\" : *\"\\ (.*\\ )\" ,*/\\ 1/" )
51
+ fi
52
+
53
+ KUBEBUILDER_VERSION=${KUBEBUILDER_VERSION# " v" }
54
+ KUBEBUILDER_VERSION_NAME=" kubebuilder_${KUBEBUILDER_VERSION} "
55
+ KUBEBUILDER_DIR=/usr/local/kubebuilder
56
+
57
+ # Check if folder containing kubebuilder executable exists and is not empty
58
+ if [ -d " $KUBEBUILDER_DIR " ]; then
59
+ if [ " $( ls -A $KUBEBUILDER_DIR ) " ]; then
60
+ echo " \n/usr/local/kubebuilder folder is not empty. Please delete or backup it before to install ${KUBEBUILDER_VERSION_NAME} "
61
+ exit 1
62
+ fi
63
+ fi
64
+
65
+ TMP_DIR=$( mktemp -d)
66
+ pushd $TMP_DIR
67
+
68
+ # Downloading Kuberbuilder compressed file using curl program
69
+ URL=" https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${KUBEBUILDER_VERSION} /${KUBEBUILDER_VERSION_NAME} _${OSEXT} _${ARCH} .tar.gz"
70
+ echo " Downloading ${KUBEBUILDER_VERSION_NAME} \nfrom $URL \n"
71
+ curl -L " $URL " | tar xz -C $TMP_DIR
72
+
73
+ echo " Downloaded executable files"
74
+ ls " ${KUBEBUILDER_VERSION_NAME} _${OSEXT} _${ARCH} /bin"
75
+
76
+ echo " Moving files to $KUBEBUILDER_DIR folder\n"
77
+ mv ${KUBEBUILDER_VERSION_NAME} _${OSEXT} _${ARCH} kubebuilder && sudo mv -f kubebuilder /usr/local/
78
+
79
+ echo " Add kubebuilder to your path; e.g copy paste in your shell and/or edit your ~/.profile file"
80
+ echo " export PATH=\$ PATH:/usr/local/kubebuilder/bin"
81
+ popd
82
+ rm -rf $TMP_DIR
0 commit comments