Skip to content

Commit ff4b9a2

Browse files
committed
Move top HW, OS, program checks. Use pushd/popd. Add missing echo commands to update PATH
1 parent dd009f2 commit ff4b9a2

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

scripts/install.sh

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,6 @@ function command_exists () {
1616
fi
1717
}
1818

19-
if [ "x${KUBEBUILDER_VERSION}" = "x" ] ; then
20-
KUBEBUILDER_VERSION=$(curl -L -s https://api.github.com/repos/kubernetes-sigs/kubebuilder/releases/latest | \
21-
grep tag_name | sed "s/ *\"tag_name\": *\"\\(.*\\)\",*/\\1/")
22-
fi
23-
24-
KUBEBUILDER_VERSION=${KUBEBUILDER_VERSION#"v"}
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-
4019
# Determine OS
4120
OS="$(uname)"
4221
case $OS in
@@ -62,17 +41,42 @@ case $HW in
6241
;;
6342
esac
6443

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+
6565
TMP_DIR=$(mktemp -d)
66+
pushd $TMP_DIR
6667

6768
# Downloading Kuberbuilder compressed file using curl program
6869
URL="https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${KUBEBUILDER_VERSION}/${KUBEBUILDER_VERSION_NAME}_${OSEXT}_${ARCH}.tar.gz"
6970
echo "Downloading ${KUBEBUILDER_VERSION_NAME}\nfrom $URL\n"
7071
curl -L "$URL"| tar xz -C $TMP_DIR
7172

7273
echo "Downloaded executable files"
73-
ls "$TMP_DIR/${KUBEBUILDER_VERSION_NAME}_${OSEXT}_${ARCH}/bin"
74+
ls "${KUBEBUILDER_VERSION_NAME}_${OSEXT}_${ARCH}/bin"
7475

7576
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+
mv ${KUBEBUILDER_VERSION_NAME}_${OSEXT}_${ARCH} kubebuilder && sudo mv -f kubebuilder /usr/local/
7778

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
7882
rm -rf $TMP_DIR

0 commit comments

Comments
 (0)