Merge "download/deploy scripts: several updates"
[releng.git] / jjb / armband / armband-download-artifact.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson AB and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 set -o errexit
11 set -o pipefail
12
13 if [[ "$JOB_NAME" =~ "merge" ]]; then
14     echo "Downloading http://$GS_URL/opnfv-gerrit-$GERRIT_CHANGE_NUMBER.properties"
15     # get the properties file for the Armband Fuel ISO built for a merged change
16     curl -f -s -o $WORKSPACE/latest.properties http://$GS_URL/opnfv-gerrit-$GERRIT_CHANGE_NUMBER.properties
17 else
18     # get the latest.properties file in order to get info regarding latest artifact
19     echo "Downloading http://$GS_URL/latest.properties"
20     curl -f -s -o $WORKSPACE/latest.properties http://$GS_URL/latest.properties
21 fi
22
23 # source the file so we get artifact metadata, it will exit if it doesn't exist
24 source latest.properties
25
26 # echo the info about artifact that is used during the deployment
27 OPNFV_ARTIFACT=${OPNFV_ARTIFACT_URL/*\/}
28 echo "Using $OPNFV_ARTIFACT for deployment"
29
30 # Releng doesn't want us to use anything but opnfv.iso for now. We comply.
31 ISO_FILE=${WORKSPACE}/opnfv.iso
32
33 # using ISOs for verify & merge jobs from local storage will be enabled later
34 if [[ ! "$JOB_NAME" =~ (verify|merge) ]]; then
35     # check if we already have the ISO to avoid redownload
36     ISOSTORE="/iso_mount/opnfv_ci/${GIT_BRANCH##*/}"
37     if [[ -f "$ISOSTORE/$OPNFV_ARTIFACT" ]]; then
38         echo "ISO exists locally. Skipping the download and using the file from ISO store"
39         ln -s $ISOSTORE/$OPNFV_ARTIFACT ${ISO_FILE}
40         echo "--------------------------------------------------------"
41         echo
42         ls -al ${ISO_FILE}
43         echo
44         echo "--------------------------------------------------------"
45         echo "Done!"
46         exit 0
47     fi
48 fi
49
50 # Use gsutils if available
51 if $(which gsutil &>/dev/null); then
52     DOWNLOAD_URL="gs://$OPNFV_ARTIFACT_URL"
53     CMD="gsutil cp ${DOWNLOAD_URL} ${ISO_FILE}"
54 else
55     # download image
56     # -f returns error if the file was not found or on server error
57     DOWNLOAD_URL="http://$OPNFV_ARTIFACT_URL"
58     CMD="curl -f -s -o ${ISO_FILE} ${DOWNLOAD_URL}"
59 fi
60
61 # log info to console
62 echo "Downloading the $INSTALLER_TYPE artifact using URL $DOWNLOAD_URL"
63 echo "This could take some time..."
64 echo "--------------------------------------------------------"
65 echo "$CMD"
66 $CMD
67 echo "--------------------------------------------------------"
68 echo "Done!"