common.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env -S bash -e
  2. set -u
  3. # Copyright 2016 The Rook Authors. All rights reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. BUILD_ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd -P)
  17. SHA256CMD=${SHA256CMD:-shasum -a 256}
  18. DOCKERCMD=${DOCKERCMD:-docker}
  19. export scriptdir
  20. scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  21. export OUTPUT_DIR=${BUILD_ROOT}/_output
  22. export WORK_DIR=${BUILD_ROOT}/.work
  23. export CACHE_DIR=${BUILD_ROOT}/.cache
  24. function ver() {
  25. local full_ver maj min bug build
  26. full_ver="$1" # functions should name input params for easier understanding
  27. maj="$(echo "${full_ver}" | cut -f1 -d'.')" # when splitting a param, name the components for easier understanding
  28. min="$(echo "${full_ver}" | cut -f2 -d'.')"
  29. bug="$(echo "${full_ver}" | cut -f3 -d'.')"
  30. build="$(echo "${full_ver}" | cut -f4 -d'.')"
  31. printf "%d%03d%03d%03d" "${maj}" "${min}" "${bug}" "${build}"
  32. }
  33. function check_git() {
  34. # git version 2.6.6+ through 2.8.3 had a bug with submodules. this makes it hard
  35. # to share a cloned directory between host and container
  36. # see https://github.com/git/git/blob/master/Documentation/RelNotes/2.8.3.txt#L33
  37. local gitversion
  38. gitversion=$(git --version | cut -d" " -f3)
  39. if (( $(ver "${gitversion}") > $(ver 2.6.6) && $(ver "${gitversion}") < $(ver 2.8.3) )); then
  40. echo WARN: you are running git version "${gitversion}" which has a bug related to relative
  41. echo WARN: submodule paths. Please consider upgrading to 2.8.3 or later
  42. fi
  43. }