init.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/bash
  2. # Copyright 2014 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. # The root of the build/dist directory
  19. KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE}")/../.." && pwd -P)"
  20. KUBE_OUTPUT_SUBPATH="${KUBE_OUTPUT_SUBPATH:-_output/local}"
  21. KUBE_OUTPUT="${KUBE_ROOT}/${KUBE_OUTPUT_SUBPATH}"
  22. KUBE_OUTPUT_BINPATH="${KUBE_OUTPUT}/bin"
  23. # Set no_proxy for localhost if behind a proxy, otherwise,
  24. # the connections to localhost in scripts will time out
  25. export no_proxy=127.0.0.1,localhost
  26. # This is a symlink to binaries for "this platform", e.g. build tools.
  27. THIS_PLATFORM_BIN="${KUBE_ROOT}/_output/bin"
  28. source "${KUBE_ROOT}/hack/lib/util.sh"
  29. source "${KUBE_ROOT}/cluster/lib/util.sh"
  30. source "${KUBE_ROOT}/cluster/lib/logging.sh"
  31. kube::log::install_errexit
  32. source "${KUBE_ROOT}/hack/lib/version.sh"
  33. source "${KUBE_ROOT}/hack/lib/golang.sh"
  34. source "${KUBE_ROOT}/hack/lib/etcd.sh"
  35. KUBE_OUTPUT_HOSTBIN="${KUBE_OUTPUT_BINPATH}/$(kube::util::host_platform)"
  36. # This emulates "readlink -f" which is not available on MacOS X.
  37. # Test:
  38. # T=/tmp/$$.$RANDOM
  39. # mkdir $T
  40. # touch $T/file
  41. # mkdir $T/dir
  42. # ln -s $T/file $T/linkfile
  43. # ln -s $T/dir $T/linkdir
  44. # function testone() {
  45. # X=$(readlink -f $1 2>&1)
  46. # Y=$(kube::readlinkdashf $1 2>&1)
  47. # if [ "$X" != "$Y" ]; then
  48. # echo readlinkdashf $1: expected "$X", got "$Y"
  49. # fi
  50. # }
  51. # testone /
  52. # testone /tmp
  53. # testone $T
  54. # testone $T/file
  55. # testone $T/dir
  56. # testone $T/linkfile
  57. # testone $T/linkdir
  58. # testone $T/nonexistant
  59. # testone $T/linkdir/file
  60. # testone $T/linkdir/dir
  61. # testone $T/linkdir/linkfile
  62. # testone $T/linkdir/linkdir
  63. function kube::readlinkdashf {
  64. # run in a subshell for simpler 'cd'
  65. (
  66. if [[ -d "$1" ]]; then # This also catch symlinks to dirs.
  67. cd "$1"
  68. pwd -P
  69. else
  70. cd $(dirname "$1")
  71. local f
  72. f=$(basename "$1")
  73. if [[ -L "$f" ]]; then
  74. readlink "$f"
  75. else
  76. echo "$(pwd -P)/${f}"
  77. fi
  78. fi
  79. )
  80. }
  81. # This emulates "realpath" which is not available on MacOS X
  82. # Test:
  83. # T=/tmp/$$.$RANDOM
  84. # mkdir $T
  85. # touch $T/file
  86. # mkdir $T/dir
  87. # ln -s $T/file $T/linkfile
  88. # ln -s $T/dir $T/linkdir
  89. # function testone() {
  90. # X=$(realpath $1 2>&1)
  91. # Y=$(kube::realpath $1 2>&1)
  92. # if [ "$X" != "$Y" ]; then
  93. # echo realpath $1: expected "$X", got "$Y"
  94. # fi
  95. # }
  96. # testone /
  97. # testone /tmp
  98. # testone $T
  99. # testone $T/file
  100. # testone $T/dir
  101. # testone $T/linkfile
  102. # testone $T/linkdir
  103. # testone $T/nonexistant
  104. # testone $T/linkdir/file
  105. # testone $T/linkdir/dir
  106. # testone $T/linkdir/linkfile
  107. # testone $T/linkdir/linkdir
  108. kube::realpath() {
  109. if [[ ! -e "$1" ]]; then
  110. echo "$1: No such file or directory" >&2
  111. return 1
  112. fi
  113. kube::readlinkdashf "$1"
  114. }