Fuel plugin for Murano with MOS integration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.sh 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. # Copyright 2016 Mirantis, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -eux
  16. ROOT="$(dirname "$(readlink -f "$0")")"
  17. MODULES_DIR="${ROOT}"/deployment_scripts/modules
  18. RPM_REPO="${ROOT}"/repositories/centos/
  19. DEB_REPO="${ROOT}"/repositories/ubuntu/
  20. # Download RPM or DEB packages and store them in the local repository directory
  21. function download_package {
  22. local package_type=$1
  23. local url=$2
  24. local wget_lvl=${3:-4}
  25. if [[ "$package_type" == 'deb' ]]; then
  26. REPO=$DEB_REPO
  27. elif [[ "$package_type" == 'rpm' ]]; then
  28. REPO=$RPM_REPO
  29. else
  30. echo "Invalid package type: $1"
  31. fi
  32. wget -P "$REPO" -A "$package_type" -nd -r -l ${wget_lvl} "$url"
  33. }
  34. # Download official Puppet module and store it in the local directory
  35. function download_puppet_module {
  36. local m_dir=$1
  37. local git_repo=$2
  38. local git_branch=$3
  39. rm -rvf "${MODULES_DIR:?}"/"$m_dir"
  40. git clone "${git_repo}" --single-branch -b "${git_branch}" "${MODULES_DIR}/${m_dir}"
  41. }
  42. # Generate version file in format:
  43. # Build: $build_date
  44. # FUEL_PLUGIN_COMMIT=$sha
  45. # $pkg_name=$pkg_version
  46. function generate_deb_version_file {
  47. local version_file="${1:-build_version}"
  48. local tmp_file=$(mktemp)
  49. echo "# Build: $(date +%Y-%m-%d-%H-%M-%S)" >> "${version_file}"
  50. echo "FUEL_PLUGIN_REF=$(git rev-parse --abbrev-ref HEAD)" >> "${version_file}"
  51. echo "FUEL_PLUGIN_COMMIT=$(git rev-parse HEAD)" >> "${version_file}"
  52. while read -d '' -r pkg; do
  53. dpkg-deb -I "${pkg}"| awk '/Package:/{name=$2}/Version:/{ver=$2;print name"="ver}' >> "${tmp_file}"
  54. done < <(find "repositories/ubuntu" -name '*.deb' -print0)
  55. cat "${tmp_file}" | sort >> "${version_file}"
  56. rm -vf "${tmp_file}"
  57. }