Merge "prototypes: xci: provision-vm-nodes: Do not provision VMs as root."
[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 APEX_PKGS="common undercloud" # removed onos for danube
7
8 # log info to console
9 echo "Downloading the Apex artifact. This could take some time..."
10 echo "--------------------------------------------------------"
11 echo
12
13 [[ -d $BUILD_DIRECTORY ]] || mkdir -p $BUILD_DIRECTORY
14
15 if [[ "$ARTIFACT_VERSION" =~ dev ]]; then
16   # dev build
17   GERRIT_PATCHSET_NUMBER=$(echo $GERRIT_REFSPEC | grep -Eo '[0-9]+$')
18   export OPNFV_ARTIFACT_VERSION="dev${GERRIT_CHANGE_NUMBER}_${GERRIT_PATCHSET_NUMBER}"
19   # get build artifact
20   pushd ${BUILD_DIRECTORY} > /dev/null
21   echo "Downloading packaged dev build: apex-${OPNFV_ARTIFACT_VERSION}.tar.gz"
22   curl --fail -s -o $BUILD_DIRECTORY/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz http://$GS_URL/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz
23   tar -xvf apex-${OPNFV_ARTIFACT_VERSION}.tar.gz
24   popd > /dev/null
25 else
26   echo "Will download RPMs and ISO..."
27
28   # Must be RPMs/ISO
29   export OPNFV_ARTIFACT_VERSION=$(date -u +"%Y-%m-%d")
30   echo "Downloading opnfv-${OPNFV_ARTIFACT_VERSION}.properties"
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/opnfv-$OPNFV_ARTIFACT_VERSION.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=${RPM_INSTALL_PATH}/$(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   for pkg in ${APEX_PKGS}; do
45     RPM_LIST+=" ${RPM_INSTALL_PATH}/opnfv-apex-${pkg}-${VERSION_EXTENSION}.noarch.rpm"
46   done
47
48   # remove old / install new RPMs
49   if rpm -q opnfv-apex > /dev/null; then
50     INSTALLED_RPMS=$(rpm -qa | grep apex)
51     if [ -n "$INSTALLED_RPMS" ]; then
52       sudo yum remove -y ${INSTALLED_RPMS}
53     fi
54   fi
55   if ! sudo yum install -y $RPM_LIST; then
56     echo "Unable to install new RPMs: $RPM_LIST"
57     exit 1
58   fi
59
60   # log info to console
61   echo "Downloading the ISO artifact using URL http://$OPNFV_ARTIFACT_URL"
62   echo "--------------------------------------------------------"
63   echo
64
65   # Download ISO
66   curl --fail -s -o $BUILD_DIRECTORY/apex.iso http://$OPNFV_ARTIFACT_URL > gsutil.iso.log 2>&1
67
68 fi
69
70 # TODO: Uncomment these lines to verify SHA512SUMs once the sums are
71 # fixed.
72 # echo "$OPNFV_ARTIFACT_SHA512SUM $BUILD_DIRECTORY/apex.iso" | sha512sum -c
73 # echo "$OPNFV_RPM_SHA512SUM $BUILD_DIRECTORY/$(basename $OPNFV_RPM_URL)" | sha512sum -c
74
75 # list the files
76 ls -al $BUILD_DIRECTORY
77
78 echo
79 echo "--------------------------------------------------------"
80 echo "Done!"