yetus-wrapper 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. 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. set -o pipefail
  17. ## @description Print a message to stderr
  18. ## @audience public
  19. ## @stability stable
  20. ## @replaceable no
  21. ## @param string
  22. function yetus_error
  23. {
  24. echo "$*" 1>&2
  25. }
  26. ## @description Given a filename or dir, return the absolute version of it
  27. ## @audience public
  28. ## @stability stable
  29. ## @param directory
  30. ## @replaceable no
  31. ## @return 0 success
  32. ## @return 1 failure
  33. ## @return stdout abspath
  34. function yetus_abs
  35. {
  36. declare obj=$1
  37. declare dir
  38. declare fn
  39. if [[ ! -e ${obj} ]]; then
  40. return 1
  41. elif [[ -d ${obj} ]]; then
  42. dir=${obj}
  43. else
  44. dir=$(dirname -- "${obj}")
  45. fn=$(basename -- "${obj}")
  46. fn="/${fn}"
  47. fi
  48. dir=$(cd -P -- "${dir}" >/dev/null 2>/dev/null && pwd -P)
  49. if [[ $? = 0 ]]; then
  50. echo "${dir}${fn}"
  51. return 0
  52. fi
  53. return 1
  54. }
  55. function version_ge()
  56. {
  57. test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1";
  58. }
  59. WANTED="$1"
  60. shift
  61. ARGV=("$@")
  62. HADOOP_YETUS_VERSION=${HADOOP_YETUS_VERSION:-0.13.0}
  63. BIN=$(yetus_abs "${BASH_SOURCE-$0}")
  64. BINDIR=$(dirname "${BIN}")
  65. ## HADOOP_YETUS_VERSION >= 0.9.0 the tarball named with apache-yetus prefix
  66. if version_ge "${HADOOP_YETUS_VERSION}" "0.9.0"; then
  67. YETUS_PREFIX=apache-yetus
  68. else
  69. YETUS_PREFIX=yetus
  70. fi
  71. ###
  72. ### if YETUS_HOME is set, then try to use it
  73. ###
  74. if [[ -n "${YETUS_HOME}" && -x "${YETUS_HOME}/bin/${WANTED}" ]]; then
  75. exec "${YETUS_HOME}/bin/${WANTED}" "${ARGV[@]}"
  76. fi
  77. #
  78. # this directory is ignored by git and maven
  79. #
  80. HADOOP_PATCHPROCESS=${HADOOP_PATCHPROCESS:-"${BINDIR}/../../patchprocess"}
  81. if [[ ! -d "${HADOOP_PATCHPROCESS}" ]]; then
  82. mkdir -p "${HADOOP_PATCHPROCESS}"
  83. fi
  84. mytmpdir=$(yetus_abs "${HADOOP_PATCHPROCESS}")
  85. if [[ $? != 0 ]]; then
  86. yetus_error "yetus-dl: Unable to cwd to ${HADOOP_PATCHPROCESS}"
  87. exit 1
  88. fi
  89. HADOOP_PATCHPROCESS=${mytmpdir}
  90. ##
  91. ## if we've already DL'd it, then short cut
  92. ##
  93. if [[ -x "${HADOOP_PATCHPROCESS}/${YETUS_PREFIX}-${HADOOP_YETUS_VERSION}/bin/${WANTED}" ]]; then
  94. exec "${HADOOP_PATCHPROCESS}/${YETUS_PREFIX}-${HADOOP_YETUS_VERSION}/bin/${WANTED}" "${ARGV[@]}"
  95. fi
  96. ##
  97. ## need to DL, etc
  98. ##
  99. BASEURL="https://archive.apache.org/dist/yetus/${HADOOP_YETUS_VERSION}/"
  100. TARBALL="${YETUS_PREFIX}-${HADOOP_YETUS_VERSION}-bin.tar"
  101. GPGBIN=$(command -v gpg)
  102. CURLBIN=$(command -v curl)
  103. pushd "${HADOOP_PATCHPROCESS}" >/dev/null
  104. if [[ $? != 0 ]]; then
  105. yetus_error "ERROR: yetus-dl: Cannot pushd to ${HADOOP_PATCHPROCESS}"
  106. exit 1
  107. fi
  108. if [[ -n "${CURLBIN}" ]]; then
  109. "${CURLBIN}" -f -s -L -O "${BASEURL}/${TARBALL}.gz"
  110. if [[ $? != 0 ]]; then
  111. yetus_error "ERROR: yetus-dl: unable to download ${BASEURL}/${TARBALL}.gz"
  112. exit 1
  113. fi
  114. else
  115. yetus_error "ERROR: yetus-dl requires curl."
  116. exit 1
  117. fi
  118. if [[ -n "${GPGBIN}" ]]; then
  119. mkdir -p .gpg
  120. if [[ $? != 0 ]]; then
  121. yetus_error "ERROR: yetus-dl: Unable to create ${HADOOP_PATCHPROCESS}/.gpg"
  122. exit 1
  123. fi
  124. chmod -R 700 .gpg
  125. if [[ $? != 0 ]]; then
  126. yetus_error "ERROR: yetus-dl: Unable to chmod ${HADOOP_PATCHPROCESS}/.gpg"
  127. exit 1
  128. fi
  129. "${CURLBIN}" -s -L -o KEYS_YETUS https://dist.apache.org/repos/dist/release/yetus/KEYS
  130. if [[ $? != 0 ]]; then
  131. yetus_error "ERROR: yetus-dl: unable to fetch https://dist.apache.org/repos/dist/release/yetus/KEYS"
  132. exit 1
  133. fi
  134. "${CURLBIN}" -s -L -O "${BASEURL}/${TARBALL}.gz.asc"
  135. if [[ $? != 0 ]]; then
  136. yetus_error "ERROR: yetus-dl: unable to fetch ${BASEURL}/${TARBALL}.gz.asc"
  137. exit 1
  138. fi
  139. "${GPGBIN}" --homedir "${HADOOP_PATCHPROCESS}/.gpg" --import "${HADOOP_PATCHPROCESS}/KEYS_YETUS" >/dev/null 2>&1
  140. if [[ $? != 0 ]]; then
  141. yetus_error "ERROR: yetus-dl: gpg unable to import ${HADOOP_PATCHPROCESS}/KEYS_YETUS"
  142. exit 1
  143. fi
  144. "${GPGBIN}" --homedir "${HADOOP_PATCHPROCESS}/.gpg" --verify "${TARBALL}.gz.asc" >/dev/null 2>&1
  145. if [[ $? != 0 ]]; then
  146. yetus_error "ERROR: yetus-dl: gpg verify of tarball in ${HADOOP_PATCHPROCESS} failed"
  147. exit 1
  148. fi
  149. fi
  150. gunzip -c "${TARBALL}.gz" | tar xpf -
  151. if [[ $? != 0 ]]; then
  152. yetus_error "ERROR: ${TARBALL}.gz is corrupt. Investigate and then remove ${HADOOP_PATCHPROCESS} to try again."
  153. exit 1
  154. fi
  155. if [[ -x "${HADOOP_PATCHPROCESS}/${YETUS_PREFIX}-${HADOOP_YETUS_VERSION}/bin/${WANTED}" ]]; then
  156. popd >/dev/null
  157. exec "${HADOOP_PATCHPROCESS}/${YETUS_PREFIX}-${HADOOP_YETUS_VERSION}/bin/${WANTED}" "${ARGV[@]}"
  158. fi
  159. ##
  160. ## give up
  161. ##
  162. yetus_error "ERROR: ${WANTED} is not part of Apache Yetus ${HADOOP_YETUS_VERSION}"
  163. exit 1