Skip to content

Commit 997b1dd

Browse files
committed
feat(install.sh): download and unpack the compressed file
Since v1.18.0 there are compressed files available under the `bundle/` directory in releases.crossplane.io. This commit adds the functionality of downloading the compressed file and unpacking it, instead of downloading the binary, which would save some bandwidth. In order to download/unpack a compressed file, a new env var needs to be passed COMPRESSED=True (or true), for example: `COMPRESSED=True XP_VERSION="v1.18.0" ./install.sh` Related PR: crossplane/docs#929 Signed-off-by: Theo Chatzimichos <[email protected]>
1 parent 8820ea1 commit 997b1dd

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

install.sh

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ arch=$(uname -m)
1010
OS=${OS:-"${os}"}
1111
ARCH=${ARCH:-"${arch}"}
1212
OS_ARCH=""
13+
COMPRESSED=${COMPRESSED:-"False"}
1314

1415
BIN=${BIN:-crank}
1516

@@ -61,16 +62,42 @@ case $OS in
6162
;;
6263
esac
6364

64-
url="https://releases.crossplane.io/${XP_CHANNEL}/${XP_VERSION}/bin/${OS_ARCH}/${BIN}"
65-
if ! curl -sfLo crossplane "${url}"; then
66-
echo "Failed to download Crossplane CLI. Please make sure version ${XP_VERSION} exists on channel ${XP_CHANNEL}."
67-
exit 1
65+
_compr=`echo $COMPRESSED | tr '[:upper:]' '[:lower:]'`
66+
67+
if [ "${_compr}" = "true" ]; then
68+
url_dir="bundle"
69+
url_file="crank.tar.gz"
70+
url_error="a compressed file for "
71+
else
72+
url_dir="bin"
73+
url_file="${BIN}"
74+
url_error=""
75+
fi
76+
77+
url="https://releases.crossplane.io/${XP_CHANNEL}/${XP_VERSION}/${url_dir}/${OS_ARCH}/${url_file}"
78+
79+
if ! curl -sfL "${url}" -o "${url_file}"; then
80+
echo "Failed to download Crossplane CLI. Please make sure ${url_error}version ${XP_VERSION} exists on channel ${XP_CHANNEL}."
81+
exit 1
82+
fi
83+
84+
if [ "${_compr}" = "true" ]; then
85+
if ! tar xzf "${url_file}"; then
86+
echo "Failed to unpack the Crossplane CLI compressed file."
87+
exit 1
88+
fi
89+
if ! mv "${BIN}" crossplane; then
90+
echo "Failed to rename the unpacked Crossplane CLI binary: \"${BIN}\". Make sure it exists inside the compressed file."
91+
fi
92+
rm "${BIN}.sha256" "${url_file}"
93+
else
94+
mv "${url_file}" crossplane
6895
fi
6996

7097
chmod +x crossplane
7198

7299
echo "crossplane CLI downloaded successfully! Run the following commands to finish installing it:"
73-
echo
100+
echo
74101
echo sudo mv crossplane /usr/local/bin
75102
echo crossplane --help
76103
echo

0 commit comments

Comments
 (0)