Merge "Pass common maven options to deploy file builder"
[releng/global-jjb.git] / shell / packer-install.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
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
14
15 # $PACKER_VERSION        : Define a packer version passed as job paramter
16
17 PACKER_VERSION="${PACKER_VERSION:-1.0.2}"
18
19 # Ensure we fail the job if any steps fail.
20 set -eu -o pipefail
21 # Default packer binary made available on the build image
22 packer_bin="/usr/local/bin/packer.io"
23
24 if hash "$packer_bin" 2>/dev/null; then
25     echo "packer.io command is available."
26 else
27     echo "packer.io command not is available. Installing packer ..."
28     # Installs Hashicorp's Packer binary, required for verify & merge packer jobs
29     pushd packer
30     wget "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip"
31     mkdir -p "${WORKSPACE}/bin"
32     unzip "packer_${PACKER_VERSION}_linux_amd64.zip" -d ${WORKSPACE}/bin/
33     # rename packer to avoid conflict with binary in cracklib
34     mv ${WORKSPACE}/bin/packer "${WORKSPACE}/bin/packer.io"
35     popd
36 fi