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