X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=blobdiff_plain;f=shell%2Fpacker-install.sh;h=ada68ab99061d01f8d28a794cf43875382fb22c3;hb=refs%2Fheads%2Fv0.26.x;hp=eb303f6e0416e5d01053ab2506a4fd9d28f2bbf8;hpb=10821edc619b09e4623884b02900c39431f8a809;p=releng%2Fglobal-jjb.git diff --git a/shell/packer-install.sh b/shell/packer-install.sh index eb303f6e..ada68ab9 100644 --- a/shell/packer-install.sh +++ b/shell/packer-install.sh @@ -12,25 +12,39 @@ echo "---> packer-install.sh" # The script checks for the packer binaries and installs the binary # if its not available -# $PACKER_VERSION : Define a packer version passed as job paramter - -PACKER_VERSION="${PACKER_VERSION:-1.0.2}" - # Ensure we fail the job if any steps fail. set -eu -o pipefail -# Default packer binary made available on the build image -packer_bin="/usr/local/bin/packer.io" -if hash "$packer_bin" 2>/dev/null; then - echo "packer.io command is available." -else - echo "packer.io command not is available. Installing packer ..." +# $PACKER_VERSION : Define a packer version passed as job paramter +PACKER_VERSION="${PACKER_VERSION:-1.2.5}" +export PATH="${WORKSPACE}/bin:$PATH" + +packer_install() { # Installs Hashicorp's Packer binary, required for verify & merge packer jobs - pushd packer - wget "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip" + pushd "${WORKSPACE}" + wget -nv "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip" mkdir -p "${WORKSPACE}/bin" - unzip "packer_${PACKER_VERSION}_linux_amd64.zip" -d ${WORKSPACE}/bin/ + unzip "packer_${PACKER_VERSION}_linux_amd64.zip" -d "${WORKSPACE}/bin/" # rename packer to avoid conflict with binary in cracklib - mv ${WORKSPACE}/bin/packer "${WORKSPACE}/bin/packer.io" + mv "${WORKSPACE}/bin/packer" "${WORKSPACE}/bin/packer.io" popd +} + +# Functions to compare semantic versions x.y.z +version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; } +version_le() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" == "$1"; } +version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; } +version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; } + +if hash packer.io 2>/dev/null; then + CURRENT_VERSION="$(packer.io --version)" + if version_lt $CURRENT_VERSION $PACKER_VERSION; then + echo "Packer version $CURRENT_VERSION installed is less than $PACKER_VERSION available, updating Packer." + packer_install + else + echo "Packer version installed $CURRENT_VERSION is greater than or equal to the required minimum version $PACKER_VERSION." + fi +else + echo "Packer binary not available, installing Packer version $PACKER_VERSION." + packer_install fi