a64c80e5c0f9ee98b5a893ea1bed74a43687c85f
[releng.git] / jjb / daisy4nfv / daisy4nfv-download-artifact.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2016 ZTE Coreporation and others.
4 # hu.zhijiang@zte.com.cn
5 # sun.jing22@zte.com.cn
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11 set -o errexit
12 set -o pipefail
13
14 # use proxy url to replace the nomral URL, for googleusercontent.com will be blocked randomly
15 [[ "$NODE_NAME" =~ (zte) ]] && GS_URL=${GS_BASE_PROXY%%/*}/$GS_URL
16
17 if [[ "$JOB_NAME" =~ "merge" ]]; then
18     echo "Downloading http://$GS_URL/opnfv-gerrit-$GERRIT_CHANGE_NUMBER.properties"
19     # get the properties file for the Daisy4nfv BIN built for a merged change
20     curl -L -s -o $WORKSPACE/latest.properties http://$GS_URL/opnfv-gerrit-$GERRIT_CHANGE_NUMBER.properties
21 else
22     # get the latest.properties file in order to get info regarding latest artifact
23     echo "Downloading http://$GS_URL/latest.properties"
24     curl -L -s -o $WORKSPACE/latest.properties http://$GS_URL/latest.properties
25 fi
26
27 # check if we got the file
28 [[ -f $WORKSPACE/latest.properties ]] || exit 1
29
30 # source the file so we get artifact metadata
31 source $WORKSPACE/latest.properties
32
33 # echo the info about artifact that is used during the deployment
34 OPNFV_ARTIFACT=${OPNFV_ARTIFACT_URL/*\/}
35 echo "Using $OPNFV_ARTIFACT for deployment"
36
37 [[ "$NODE_NAME" =~ (zte) ]] && OPNFV_ARTIFACT_URL=${GS_BASE_PROXY%%/*}/$OPNFV_ARTIFACT_URL
38
39 if [[ ! "$JOB_NAME" =~ (verify|merge) ]]; then
40     # check if we already have the image to avoid redownload
41     BINSTORE="/bin_mount/opnfv_ci/${BRANCH##*/}"
42     if [[ -f "$BINSTORE/$OPNFV_ARTIFACT" && ! -z $OPNFV_ARTIFACT_SHA512SUM ]]; then
43         echo "BIN exists locally. Starting to check the sha512sum."
44         if [[ $OPNFV_ARTIFACT_SHA512SUM = $(sha512sum -b $BINSTORE/$OPNFV_ARTIFACT | cut -d' ' -f1) ]]; then
45             echo "Sha512sum is verified. Skipping the download and using the file from BIN store."
46             ln -s $BINSTORE/$OPNFV_ARTIFACT $WORKSPACE/opnfv.bin
47             echo "--------------------------------------------------------"
48             echo
49             ls -al $WORKSPACE/opnfv.bin
50             echo
51             echo "--------------------------------------------------------"
52             echo "Done!"
53             exit 0
54         fi
55     fi
56 fi
57
58 # log info to console
59 echo "Downloading the $INSTALLER_TYPE artifact using URL http://$OPNFV_ARTIFACT_URL"
60 echo "This could take some time... Now the time is $(date -u)"
61 echo "--------------------------------------------------------"
62 echo
63
64 # download the file
65 if [[ "$NODE_NAME" =~ (zte) ]] && [ -x "$(command -v aria2c)" ]; then
66     DOWNLOAD_CMD="aria2c -x 3 --allow-overwrite=true -d $WORKSPACE -o opnfv.bin"
67 else
68     DOWNLOAD_CMD="curl -L -s -o $WORKSPACE/opnfv.bin"
69 fi
70
71 $DOWNLOAD_CMD http://$OPNFV_ARTIFACT_URL > gsutil.bin.log 2>&1
72
73 # list the file
74 ls -al $WORKSPACE/opnfv.bin
75
76 echo
77 echo "--------------------------------------------------------"
78 echo "Done!"