clientbin.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env bash
  2. # Copyright 2016 The Kubernetes Authors.
  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 -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. KUBE_ROOT=${KUBE_ROOT:-$(dirname "${BASH_SOURCE[0]}")/..}
  19. # Detect the OS name/arch so that we can find our binary
  20. case "$(uname -s)" in
  21. Darwin)
  22. host_os=darwin
  23. ;;
  24. Linux)
  25. host_os=linux
  26. ;;
  27. *)
  28. echo "Unsupported host OS. Must be Linux or Mac OS X." >&2
  29. exit 1
  30. ;;
  31. esac
  32. case "$(uname -m)" in
  33. x86_64*)
  34. host_arch=amd64
  35. ;;
  36. i?86_64*)
  37. host_arch=amd64
  38. ;;
  39. amd64*)
  40. host_arch=amd64
  41. ;;
  42. arm*)
  43. host_arch=arm
  44. ;;
  45. aarch64*)
  46. host_arch=arm64
  47. ;;
  48. i?86*)
  49. host_arch=386
  50. ;;
  51. s390x*)
  52. host_arch=s390x
  53. ;;
  54. ppc64le*)
  55. host_arch=ppc64le
  56. ;;
  57. *)
  58. echo "Unsupported host arch. Must be x86_64, 386, arm, s390x or ppc64le." >&2
  59. exit 1
  60. ;;
  61. esac
  62. function get_bin() {
  63. bin="${1:-}"
  64. srcdir="${2:-}"
  65. if [[ "${bin}" == "" ]]; then
  66. echo "Binary name is required"
  67. exit 1
  68. fi
  69. if [[ "${srcdir}" == "" ]]; then
  70. echo "Source directory path is required"
  71. exit 1
  72. fi
  73. locations=(
  74. "${KUBE_ROOT}/_output/bin/${bin}"
  75. "${KUBE_ROOT}/_output/dockerized/bin/${host_os}/${host_arch}/${bin}"
  76. "${KUBE_ROOT}/_output/local/bin/${host_os}/${host_arch}/${bin}"
  77. "${KUBE_ROOT}/platforms/${host_os}/${host_arch}/${bin}"
  78. )
  79. # Also search for binary in bazel build tree.
  80. # The bazel go rules place binaries in subtrees like
  81. # "bazel-bin/source/path/linux_amd64_pure_stripped/binaryname", so make sure
  82. # the platform name is matched in the path.
  83. while IFS=$'\n' read -r line; do
  84. locations+=( "${line}" )
  85. done < <(find "${KUBE_ROOT}/bazel-bin/${srcdir}" -type f -executable \
  86. -path "*/${host_os}_${host_arch}*/${bin}" 2>/dev/null || true)
  87. (ls -t "${locations[@]}" 2>/dev/null || true) | head -1
  88. }
  89. function print_error() {
  90. {
  91. echo "It looks as if you don't have a compiled ${1:-} binary"
  92. echo
  93. echo "If you are running from a clone of the git repo, please run"
  94. echo "'./build/run.sh make cross'. Note that this requires having"
  95. echo "Docker installed."
  96. echo
  97. echo "If you are running from a binary release tarball, something is wrong. "
  98. echo "Look at http://kubernetes.io/ for information on how to contact the "
  99. echo "development team for help."
  100. } >&2
  101. }