68baf59da6b8af28261768918782dfcefe26c5fe
[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
43   # add back legacy support for danube
44   if [ "$BRANCH" == 'stable/danube' ]; then
45     RPM_LIST+=" opnfv-apex-common-${VERSION_EXTENSION}.noarch.rpm"
46   else
47     RPM_LIST+=" python34-opnfv-apex-${VERSION_EXTENSION}.noarch.rpm"
48   fi
49
50   # remove old / install new RPMs
51   if rpm -q opnfv-apex > /dev/null; then
52     INSTALLED_RPMS=$(rpm -qa | grep apex)
53     if [ -n "$INSTALLED_RPMS" ]; then
54       sudo yum remove -y ${INSTALLED_RPMS}
55     fi
56   fi
57   # Create an rpms dir on slave
58   mkdir -p ~/apex_rpms
59   pushd ~/apex_rpms
60   # Remove older rpms which do not match this version
61   find . ! -name "*${VERSION_EXTENSION}.noarch.rpm" -type f -exec rm -f {} +
62   # Download RPM only if changed on server
63   for rpm in $RPM_LIST; do
64     wget -N ${RPM_INSTALL_PATH}/${rpm}
65   done
66   if ! sudo yum install -y $RPM_LIST; then
67     echo "Unable to install new RPMs: $RPM_LIST"
68     exit 1
69   fi
70   popd
71 fi
72
73 # TODO: Uncomment these lines to verify SHA512SUMs once the sums are
74 # fixed.
75 # echo "$OPNFV_ARTIFACT_SHA512SUM $BUILD_DIRECTORY/apex.iso" | sha512sum -c
76 # echo "$OPNFV_RPM_SHA512SUM $BUILD_DIRECTORY/$(basename $OPNFV_RPM_URL)" | sha512sum -c
77
78 # list the files
79 ls -al $BUILD_DIRECTORY
80
81 echo
82 echo "--------------------------------------------------------"
83 echo "Done!"