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