From 0c5fc5e694c54000fbc1f2a2a7dec028b91844b4 Mon Sep 17 00:00:00 2001 From: Timo Walter Date: Mon, 21 Sep 2020 15:16:17 +0200 Subject: [PATCH 1/2] Extend the install_kustomize.sh to enable the installation of specific versions --- hack/install_kustomize.sh | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/hack/install_kustomize.sh b/hack/install_kustomize.sh index 6e152d6dc..099767741 100755 --- a/hack/install_kustomize.sh +++ b/hack/install_kustomize.sh @@ -1,10 +1,24 @@ #!/bin/bash -# Downloads the most recently released kustomize binary -# to your current working directory. +# If no argument is given -> Downloads the most recently released +# kustomize binary to your current working directory. +# (e.g. 'install_kustomize.sh') +# +# If an argument is given -> Downloads the specified version of the +# kustomize binary to your current working directory. +# (e.g. 'install_kustomize.sh 3.8.2') # # Fails if the file already exists. +if [ -z "$1" ] + then + echo "No version specified. Downloading the most recently released kustomize binary." + version="" + else + echo "Downloading the kustomize binary version $1." + version=$1 +fi + where=$PWD if [ -f $where/kustomize ]; then echo "A file named kustomize already exists (remove it first)." @@ -17,7 +31,7 @@ if [[ ! "$tmpDir" || ! -d "$tmpDir" ]]; then exit 1 fi -function cleanup { +function cleanup { rm -rf "$tmpDir" } @@ -36,11 +50,17 @@ curl -s https://api.github.com/repos/kubernetes-sigs/kustomize/releases |\ grep browser_download |\ grep $opsys |\ cut -d '"' -f 4 |\ - grep /kustomize/v |\ + grep /kustomize/v$version |\ sort | tail -n 1 |\ xargs curl -s -O -L -tar xzf ./kustomize_v*_${opsys}_amd64.tar.gz +if [ -e ./kustomize_v*_${opsys}_amd64.tar.gz ] +then + tar xzf ./kustomize_v*_${opsys}_amd64.tar.gz +else + echo "Error: kustomize binary with the version $version does not exist!" + exit 1 +fi cp ./kustomize $where From 6a9e75ee0d558683b989fe42e7edc02e84c990a9 Mon Sep 17 00:00:00 2001 From: Timo Walter Date: Mon, 21 Sep 2020 23:09:16 +0200 Subject: [PATCH 2/2] Improve the "install_kustomize.sh" script - fix formatting - remove unnecessary echo statements --- hack/install_kustomize.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hack/install_kustomize.sh b/hack/install_kustomize.sh index 099767741..4c4993466 100755 --- a/hack/install_kustomize.sh +++ b/hack/install_kustomize.sh @@ -10,12 +10,9 @@ # # Fails if the file already exists. -if [ -z "$1" ] - then - echo "No version specified. Downloading the most recently released kustomize binary." +if [ -z "$1" ]; then version="" else - echo "Downloading the kustomize binary version $1." version=$1 fi @@ -54,8 +51,7 @@ curl -s https://api.github.com/repos/kubernetes-sigs/kustomize/releases |\ sort | tail -n 1 |\ xargs curl -s -O -L -if [ -e ./kustomize_v*_${opsys}_amd64.tar.gz ] -then +if [ -e ./kustomize_v*_${opsys}_amd64.tar.gz ]; then tar xzf ./kustomize_v*_${opsys}_amd64.tar.gz else echo "Error: kustomize binary with the version $version does not exist!"