init.sh 3.4 KB

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