yetus-wrapper 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. WANTED="$1"
  56. shift
  57. ARGV=("$@")
  58. HADOOP_YETUS_VERSION=${HADOOP_YETUS_VERSION:-0.3.0}
  59. BIN=$(yetus_abs "${BASH_SOURCE-$0}")
  60. BINDIR=$(dirname "${BIN}")
  61. ###
  62. ### if YETUS_HOME is set, then try to use it
  63. ###
  64. if [[ -n "${YETUS_HOME}"
  65. && -x "${YETUS_HOME}/bin/${WANTED}" ]]; then
  66. exec "${YETUS_HOME}/bin/${WANTED}" "${ARGV[@]}"
  67. fi
  68. #
  69. # this directory is ignored by git and maven
  70. #
  71. HADOOP_PATCHPROCESS=${HADOOP_PATCHPROCESS:-"${BINDIR}/../../patchprocess"}
  72. if [[ ! -d "${HADOOP_PATCHPROCESS}" ]]; then
  73. mkdir -p "${HADOOP_PATCHPROCESS}"
  74. fi
  75. mytmpdir=$(yetus_abs "${HADOOP_PATCHPROCESS}")
  76. if [[ $? != 0 ]]; then
  77. yetus_error "yetus-dl: Unable to cwd to ${HADOOP_PATCHPROCESS}"
  78. exit 1
  79. fi
  80. HADOOP_PATCHPROCESS=${mytmpdir}
  81. ##
  82. ## if we've already DL'd it, then short cut
  83. ##
  84. if [[ -x "${HADOOP_PATCHPROCESS}/yetus-${HADOOP_YETUS_VERSION}/bin/${WANTED}" ]]; then
  85. exec "${HADOOP_PATCHPROCESS}/yetus-${HADOOP_YETUS_VERSION}/bin/${WANTED}" "${ARGV[@]}"
  86. fi
  87. ##
  88. ## need to DL, etc
  89. ##
  90. BASEURL="https://archive.apache.org/dist/yetus/${HADOOP_YETUS_VERSION}/"
  91. TARBALL="yetus-${HADOOP_YETUS_VERSION}-bin.tar"
  92. GPGBIN=$(command -v gpg)
  93. CURLBIN=$(command -v curl)
  94. pushd "${HADOOP_PATCHPROCESS}" >/dev/null
  95. if [[ $? != 0 ]]; then
  96. yetus_error "ERROR: yetus-dl: Cannot pushd to ${HADOOP_PATCHPROCESS}"
  97. exit 1
  98. fi
  99. if [[ -n "${CURLBIN}" ]]; then
  100. "${CURLBIN}" -f -s -L -O "${BASEURL}/${TARBALL}.gz"
  101. if [[ $? != 0 ]]; then
  102. yetus_error "ERROR: yetus-dl: unable to download ${BASEURL}/${TARBALL}.gz"
  103. exit 1
  104. fi
  105. else
  106. yetus_error "ERROR: yetus-dl requires curl."
  107. exit 1
  108. fi
  109. if [[ -n "${GPGBIN}" ]]; then
  110. mkdir -p .gpg
  111. if [[ $? != 0 ]]; then
  112. yetus_error "ERROR: yetus-dl: Unable to create ${HADOOP_PATCHPROCESS}/.gpg"
  113. exit 1
  114. fi
  115. chmod -R 700 .gpg
  116. if [[ $? != 0 ]]; then
  117. yetus_error "ERROR: yetus-dl: Unable to chmod ${HADOOP_PATCHPROCESS}/.gpg"
  118. exit 1
  119. fi
  120. "${CURLBIN}" -s -L -o KEYS_YETUS https://dist.apache.org/repos/dist/release/yetus/KEYS
  121. if [[ $? != 0 ]]; then
  122. yetus_error "ERROR: yetus-dl: unable to fetch https://dist.apache.org/repos/dist/release/yetus/KEYS"
  123. exit 1
  124. fi
  125. "${CURLBIN}" -s -L -O "${BASEURL}/${TARBALL}.gz.asc"
  126. if [[ $? != 0 ]]; then
  127. yetus_error "ERROR: yetus-dl: unable to fetch ${BASEURL}/${TARBALL}.gz.asc"
  128. exit 1
  129. fi
  130. "${GPGBIN}" --homedir "${HADOOP_PATCHPROCESS}/.gpg" --import "${HADOOP_PATCHPROCESS}/KEYS_YETUS" >/dev/null 2>&1
  131. if [[ $? != 0 ]]; then
  132. yetus_error "ERROR: yetus-dl: gpg unable to import ${HADOOP_PATCHPROCESS}/KEYS_YETUS"
  133. exit 1
  134. fi
  135. "${GPGBIN}" --homedir "${HADOOP_PATCHPROCESS}/.gpg" --verify "${TARBALL}.gz.asc" >/dev/null 2>&1
  136. if [[ $? != 0 ]]; then
  137. yetus_error "ERROR: yetus-dl: gpg verify of tarball in ${HADOOP_PATCHPROCESS} failed"
  138. exit 1
  139. fi
  140. fi
  141. gunzip -c "${TARBALL}.gz" | tar xpf -
  142. if [[ $? != 0 ]]; then
  143. yetus_error "ERROR: ${TARBALL}.gz is corrupt. Investigate and then remove ${HADOOP_PATCHPROCESS} to try again."
  144. exit 1
  145. fi
  146. if [[ -x "${HADOOP_PATCHPROCESS}/yetus-${HADOOP_YETUS_VERSION}/bin/${WANTED}" ]]; then
  147. popd >/dev/null
  148. exec "${HADOOP_PATCHPROCESS}/yetus-${HADOOP_YETUS_VERSION}/bin/${WANTED}" "${ARGV[@]}"
  149. fi
  150. ##
  151. ## give up
  152. ##
  153. yetus_error "ERROR: ${WANTED} is not part of Apache Yetus ${HADOOP_YETUS_VERSION}"
  154. exit 1