Merge "fixes for docs-build.sh migration"
[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 # Configurable environment variables:
14 # ISOSTORE (/iso_mount/opnfv_ci)
15
16 if [[ "$JOB_NAME" =~ "merge" ]]; then
17     echo "Downloading http://$GS_URL/opnfv-gerrit-$GERRIT_CHANGE_NUMBER.properties"
18     # get the properties file for the Armband Fuel ISO built for a merged change
19     curl -f -s -o $WORKSPACE/latest.properties http://$GS_URL/opnfv-gerrit-$GERRIT_CHANGE_NUMBER.properties
20 else
21     # get the latest.properties file in order to get info regarding latest artifact
22     echo "Downloading http://$GS_URL/latest.properties"
23     curl -f -s -o $WORKSPACE/latest.properties http://$GS_URL/latest.properties
24 fi
25
26 # source the file so we get artifact metadata, it will exit if it doesn't exist
27 source latest.properties
28
29 # echo the info about artifact that is used during the deployment
30 OPNFV_ARTIFACT=${OPNFV_ARTIFACT_URL/*\/}
31 echo "Using $OPNFV_ARTIFACT for deployment"
32
33 # Releng doesn't want us to use anything but opnfv.iso for now. We comply.
34 ISO_FILE=${WORKSPACE}/opnfv.iso
35
36 # using ISOs for verify & merge jobs from local storage will be enabled later
37 if [[ ! "$JOB_NAME" =~ (verify|merge) ]]; then
38     # check if we already have the ISO to avoid redownload
39     ISOSTORE=${ISOSTORE:-/iso_mount/opnfv_ci}/${GIT_BRANCH##*/}
40     if [[ -f "$ISOSTORE/$OPNFV_ARTIFACT" ]]; then
41         echo "ISO exists locally. Skipping the download and using the file from ISO store"
42         ln -s $ISOSTORE/$OPNFV_ARTIFACT ${ISO_FILE}
43         echo "--------------------------------------------------------"
44         echo
45         ls -al ${ISO_FILE}
46         echo
47         echo "--------------------------------------------------------"
48         echo "Done!"
49         exit 0
50     fi
51 fi
52
53 # Use gsutils if available
54 if $(which gsutil &>/dev/null); then
55     DOWNLOAD_URL="gs://$OPNFV_ARTIFACT_URL"
56     CMD="gsutil cp ${DOWNLOAD_URL} ${ISO_FILE}"
57 else
58     # download image
59     # -f returns error if the file was not found or on server error
60     DOWNLOAD_URL="http://$OPNFV_ARTIFACT_URL"
61     CMD="curl -f -s -o ${ISO_FILE} ${DOWNLOAD_URL}"
62 fi
63
64 # log info to console
65 echo "Downloading the $INSTALLER_TYPE artifact using URL $DOWNLOAD_URL"
66 echo "This could take some time..."
67 echo "--------------------------------------------------------"
68 echo "$CMD"
69 $CMD
70 echo "--------------------------------------------------------"
71 echo "Done!"