6c0f8fe261b765e7a58d72b015b3d29edfd2ea43
[releng.git] / jjb / apex / apex-download-artifact.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4 set -o pipefail
5
6 # log info to console
7 echo "Downloading the Apex artifact. This could take some time..."
8 echo "--------------------------------------------------------"
9 echo
10
11 [[ -d $BUILD_DIRECTORY ]] || mkdir -p $BUILD_DIRECTORY
12
13 if [ -z "$DEPLOY_SCENARIO" ]; then
14   echo "Deploy scenario not set!"
15   exit 1
16 else
17   echo "Deploy scenario: ${DEPLOY_SCENARIO}"
18 fi
19
20 # if upstream we do not need to download anything
21 if [[ "$DEPLOY_SCENARIO" =~ upstream ]]; then
22   echo "Upstream deployment detected, skipping download artifact"
23 elif [[ "$ARTIFACT_VERSION" =~ dev ]]; then
24   # dev build
25   GERRIT_PATCHSET_NUMBER=$(echo $GERRIT_REFSPEC | grep -Eo '[0-9]+$')
26   export OPNFV_ARTIFACT_VERSION="dev${GERRIT_CHANGE_NUMBER}_${GERRIT_PATCHSET_NUMBER}"
27   # get build artifact
28   pushd ${BUILD_DIRECTORY} > /dev/null
29   echo "Downloading packaged dev build: apex-${OPNFV_ARTIFACT_VERSION}.tar.gz"
30   curl --fail -s -o $BUILD_DIRECTORY/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz http://$GS_URL/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz
31   tar -xvf apex-${OPNFV_ARTIFACT_VERSION}.tar.gz
32   popd > /dev/null
33 else
34   echo "Will use RPMs..."
35
36   # Must be RPMs/ISO
37   echo "Downloading latest properties file"
38
39   # get the properties file in order to get info regarding artifacts
40   curl --fail -s -o $BUILD_DIRECTORY/opnfv.properties http://$GS_URL/latest.properties
41
42   # source the file so we get OPNFV vars
43   source $BUILD_DIRECTORY/opnfv.properties
44
45   RPM_INSTALL_PATH=$(echo "http://"$OPNFV_RPM_URL | sed 's/\/'"$(basename $OPNFV_RPM_URL)"'//')
46   RPM_LIST=$(basename $OPNFV_RPM_URL)
47
48   # find version of RPM
49   VERSION_EXTENSION=$(echo $(basename $RPM_LIST) | grep -Eo '[0-9]+\.[0-9]+-([0-9]{8}|[a-z]+-[0-9]\.[0-9]+)')
50   # build RPM List which already includes base Apex RPM
51   RPM_LIST+=" opnfv-apex-undercloud-${VERSION_EXTENSION}.noarch.rpm"
52
53   # add back legacy support for danube
54   if [ "$BRANCH" == 'stable/danube' ]; then
55     RPM_LIST+=" opnfv-apex-common-${VERSION_EXTENSION}.noarch.rpm"
56   else
57     RPM_LIST+=" python34-opnfv-apex-${VERSION_EXTENSION}.noarch.rpm"
58   fi
59
60   # remove old / install new RPMs
61   if rpm -q opnfv-apex > /dev/null; then
62     INSTALLED_RPMS=$(rpm -qa | grep apex)
63     if [ -n "$INSTALLED_RPMS" ]; then
64       sudo yum remove -y ${INSTALLED_RPMS}
65     fi
66   fi
67   # Create an rpms dir on slave
68   mkdir -p ~/apex_rpms
69   pushd ~/apex_rpms
70   # Remove older rpms which do not match this version
71   find . ! -name "*${VERSION_EXTENSION}.noarch.rpm" -type f -exec rm -f {} +
72   # Download RPM only if changed on server
73   for rpm in $RPM_LIST; do
74     wget -N ${RPM_INSTALL_PATH}/${rpm}
75   done
76   if ! sudo yum install -y $RPM_LIST; then
77     echo "Unable to install new RPMs: $RPM_LIST"
78     exit 1
79   fi
80   popd
81 fi
82
83 # TODO: Uncomment these lines to verify SHA512SUMs once the sums are
84 # fixed.
85 # echo "$OPNFV_ARTIFACT_SHA512SUM $BUILD_DIRECTORY/apex.iso" | sha512sum -c
86 # echo "$OPNFV_RPM_SHA512SUM $BUILD_DIRECTORY/$(basename $OPNFV_RPM_URL)" | sha512sum -c
87
88 # list the files
89 ls -al $BUILD_DIRECTORY
90
91 echo
92 echo "--------------------------------------------------------"
93 echo "Done!"