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