summaryrefslogtreecommitdiff
path: root/pre_build_hook
blob: 3a8795f465e14f1f7f2e47de8bdb58a9df203386 (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
#!/bin/bash
# Copyright 2015 Mellanox Technologies, Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

readonly PLUGIN_DIR="$(dirname $0)"
readonly PLUGIN_VERSION=`cat ${PLUGIN_DIR}/.version`
readonly REPOSITORY_PATH='bgate.mellanox.com/openstack/mellanox_fuel_plugin'

function download {
  FILE_TYPE=$1
  FILE_NAME=$2
  case ${FILE_TYPE} in
    'bootstrap')
      PREFIX_URL=$PLUGIN_VERSION/bootstrap/latest-build
      BUILD_DIR=bootstrap/
      FILE_NAME=`curl http://${REPOSITORY_PATH}/${PREFIX_URL}/ | tr '<' '\n' | tr '>' '\n' | grep ^$FILE_NAME`
      ;;
    'rpm')
      PREFIX_URL=$PLUGIN_VERSION/repositories/centos/Packages
      BUILD_DIR=repositories/centos/Packages
      ;;
    'deb')
      PREFIX_URL=$PLUGIN_VERSION/repositories/ubuntu
      BUILD_DIR=repositories/ubuntu
      ;;
    *)
      echo "Can't download ${FILE_NAME}. File of type ${FILE_TYPE} is not supported."
      exit 1
  esac
  URL="http://${REPOSITORY_PATH}/${PREFIX_URL}/${FILE_NAME}"
  DEST_DIR="${PLUGIN_DIR}/${BUILD_DIR}"
  wget ${URL} -P ${DEST_DIR}
  if [ $? -ne 0 ]; then
    echo "Failed fetching package from: ${URL} to ${DEST_DIR}" >&2
    exit 1
  fi
}

function get_packages() {
  file_type=$1
  old_packages=$2
  files=$3
  rm -rf $old_packages
  for f in $files; do
    download $file_type $f
  done
}

old_debs="${PLUGIN_DIR}/repositories/ubuntu/*.deb"
deb_files="cirros-testvm-mellanox_0.3.2-ubuntu3_amd64.deb
           cirros-testvm-mellanox-ib_0.3.2-9_amd64.deb
           eswitchd_1.0.0-18_amd64.deb
           mlnx-ofed-fuel_4.0-2.0.0.1_amd64.deb
           lldpd_0.9.1-0_amd64.deb
           python-networking-mlnx_7.0.0-1_all.deb"
get_packages "deb" "$old_debs" "$deb_files"