summaryrefslogtreecommitdiffstats
path: root/jjb/apex/apex-download-artifact.sh
blob: bc3311d68c609c49078ad7957fc2a2cc96c76b1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail

# log info to console
echo "Downloading the Apex artifact. This could take some time..."
echo "--------------------------------------------------------"
echo

[[ -d $BUILD_DIRECTORY ]] || mkdir -p $BUILD_DIRECTORY

if [ -z "$DEPLOY_SCENARIO" ]; then
  echo "Deploy scenario not set!"
  exit 1
else
  echo "Deploy scenario: ${DEPLOY_SCENARIO}"
fi

if [[ "$ARTIFACT_VERSION" =~ dev ]]; then
  if [[ "$BRANCH" != 'stable/fraser' ]]; then
    echo "Skipping download of artifacts for master/gambia branch"
  else
    # dev build
    GERRIT_PATCHSET_NUMBER=$(echo $GERRIT_REFSPEC | grep -Eo '[0-9]+$')
    export OPNFV_ARTIFACT_VERSION="dev${GERRIT_CHANGE_NUMBER}_${GERRIT_PATCHSET_NUMBER}"
    # get build artifact
    pushd ${BUILD_DIRECTORY} > /dev/null
    echo "Downloading packaged dev build: apex-${OPNFV_ARTIFACT_VERSION}.tar.gz"
    curl --fail -s -o $BUILD_DIRECTORY/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz http://$GS_URL/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz
    tar -xvf apex-${OPNFV_ARTIFACT_VERSION}.tar.gz
    popd > /dev/null
  fi
else
  echo "Will use RPMs..."

  # Must be RPMs/ISO
  echo "Downloading latest properties file"

  # get the properties file in order to get info regarding artifacts
  curl --fail -s -o $BUILD_DIRECTORY/opnfv.properties http://$GS_URL/latest.properties

  # source the file so we get OPNFV vars
  source $BUILD_DIRECTORY/opnfv.properties

  RPM_INSTALL_PATH=$(echo "http://"$OPNFV_RPM_URL | sed 's/\/'"$(basename $OPNFV_RPM_URL)"'//')
  RPM_LIST=$(basename $OPNFV_RPM_URL)
  # find version of RPM
  VERSION_EXTENSION=$(echo $(basename $RPM_LIST) | grep -Eo '[0-9]+\.[0-9]+-([0-9]{8}|[a-z]+-[0-9]\.[0-9]+)')
  if [ "$BRANCH" == 'stable/fraser' ]; then
    # build RPM List which already includes base Apex RPM
    RPM_LIST+=" opnfv-apex-undercloud-${VERSION_EXTENSION}.noarch.rpm"
    RPM_LIST+=" python34-opnfv-apex-${VERSION_EXTENSION}.noarch.rpm"
  fi

  # remove old / install new RPMs
  if rpm -q python34-opnfv-apex > /dev/null; then
    INSTALLED_RPMS=$(rpm -qa | grep apex)
    if [ -n "$INSTALLED_RPMS" ]; then
      sudo yum remove -y ${INSTALLED_RPMS}
    fi
  fi
  # Create an rpms dir on slave
  mkdir -p ~/apex_rpms
  pushd ~/apex_rpms
  # Remove older rpms which do not match this version
  find . ! -name "*${VERSION_EXTENSION}.noarch.rpm" -type f -exec rm -f {} +
  # Download RPM only if changed on server
  for rpm in $RPM_LIST; do
    wget -N ${RPM_INSTALL_PATH}/${rpm}
  done
  if ! sudo yum install -y $RPM_LIST; then
    echo "Unable to install new RPMs: $RPM_LIST"
    exit 1
  fi
  popd
fi

# TODO: Uncomment these lines to verify SHA512SUMs once the sums are
# fixed.
# echo "$OPNFV_ARTIFACT_SHA512SUM $BUILD_DIRECTORY/apex.iso" | sha512sum -c
# echo "$OPNFV_RPM_SHA512SUM $BUILD_DIRECTORY/$(basename $OPNFV_RPM_URL)" | sha512sum -c

# list the files
ls -al $BUILD_DIRECTORY

echo
echo "--------------------------------------------------------"
echo "Done!"