Merge "Add script to print all creds in Jenkins"
[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.1.3}"
18
19 # Ensure we fail the job if any steps fail.
20 set -eu -o pipefail
21
22 if hash packer.io 2>/dev/null; then
23     echo "packer.io command is available."
24 else
25     echo "packer.io command not is available. Installing packer ..."
26     # Installs Hashicorp's Packer binary, required for verify & merge packer jobs
27     pushd "${WORKSPACE}"
28     wget -nv "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip"
29     mkdir -p "${WORKSPACE}/bin"
30     unzip "packer_${PACKER_VERSION}_linux_amd64.zip" -d "${WORKSPACE}/bin/"
31     # rename packer to avoid conflict with binary in cracklib
32     mv "${WORKSPACE}/bin/packer" "${WORKSPACE}/bin/packer.io"
33     popd
34 fi