2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> packer-install.sh"
12 # The script checks for the packer binaries and installs the binary
13 # if its not available
15 # Ensure we fail the job if any steps fail.
18 # $PACKER_VERSION : Define a packer version passed as job paramter
19 PACKER_VERSION="${PACKER_VERSION:-1.2.3}"
20 export PATH="${WORKSPACE}/bin:$PATH"
23 # Installs Hashicorp's Packer binary, required for verify & merge packer jobs
25 wget -nv "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip"
26 mkdir -p "${WORKSPACE}/bin"
27 unzip "packer_${PACKER_VERSION}_linux_amd64.zip" -d "${WORKSPACE}/bin/"
28 # rename packer to avoid conflict with binary in cracklib
29 mv "${WORKSPACE}/bin/packer" "${WORKSPACE}/bin/packer.io"
33 # Functions to compare semantic versions x.y.z
34 version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
35 version_le() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" == "$1"; }
36 version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; }
37 version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
39 if hash packer.io 2>/dev/null; then
40 CURRENT_VERSION="$(packer.io --version)"
41 if version_lt "$CURRENT_VERSION" "$PACKER_VERSION"; then
42 echo "Packer version $CURRENT_VERSION installed is less than $PACKER_VERSION available, updating Packer."
45 echo "Packer version installed $CURRENT_VERSION is greater than or equal to the required minimum version $PACKER_VERSION."
48 echo "Packer binary not available, installing Packer version $PACKER_VERSION."