yetus-wrapper 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. # you must be this high to ride the ride
  17. if [[ -z "${BASH_VERSINFO[0]}" ]] \
  18. || [[ "${BASH_VERSINFO[0]}" -lt 3 ]] \
  19. || [[ "${BASH_VERSINFO[0]}" -eq 3 && "${BASH_VERSINFO[1]}" -lt 2 ]]; then
  20. echo "bash v3.2+ is required. Sorry."
  21. exit 1
  22. fi
  23. set -o pipefail
  24. ## @description Print a message to stderr
  25. ## @audience public
  26. ## @stability stable
  27. ## @replaceable no
  28. ## @param string
  29. function yetus_error
  30. {
  31. echo "$*" 1>&2
  32. }
  33. ## @description Given a filename or dir, return the absolute version of it
  34. ## @audience public
  35. ## @stability stable
  36. ## @param directory
  37. ## @replaceable no
  38. ## @return 0 success
  39. ## @return 1 failure
  40. ## @return stdout abspath
  41. function yetus_abs
  42. {
  43. declare obj=$1
  44. declare dir
  45. declare fn
  46. declare dirret
  47. if [[ ! -e ${obj} ]]; then
  48. return 1
  49. elif [[ -d ${obj} ]]; then
  50. dir=${obj}
  51. else
  52. dir=$(dirname -- "${obj}")
  53. fn=$(basename -- "${obj}")
  54. fn="/${fn}"
  55. fi
  56. dir=$(cd -P -- "${dir}" >/dev/null 2>/dev/null && pwd -P)
  57. dirret=$?
  58. if [[ ${dirret} = 0 ]]; then
  59. echo "${dir}${fn}"
  60. return 0
  61. fi
  62. return 1
  63. }
  64. WANTED="$1"
  65. shift
  66. ARGV=("$@")
  67. HADOOP_YETUS_VERSION=${HADOOP_YETUS_VERSION:-0.4.0}
  68. BIN=$(yetus_abs "${BASH_SOURCE-$0}")
  69. BINDIR=$(dirname "${BIN}")
  70. ###
  71. ### if YETUS_HOME is set, then try to use it
  72. ###
  73. if [[ -n "${YETUS_HOME}"
  74. && -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. ret=$?
  86. if [[ ${ret} != 0 ]]; then
  87. yetus_error "yetus-dl: Unable to cwd to ${HADOOP_PATCHPROCESS}"
  88. exit 1
  89. fi
  90. HADOOP_PATCHPROCESS=${mytmpdir}
  91. ##
  92. ## if we've already DL'd it, then short cut
  93. ##
  94. if [[ -x "${HADOOP_PATCHPROCESS}/yetus-${HADOOP_YETUS_VERSION}/bin/${WANTED}" ]]; then
  95. exec "${HADOOP_PATCHPROCESS}/yetus-${HADOOP_YETUS_VERSION}/bin/${WANTED}" "${ARGV[@]}"
  96. fi
  97. ##
  98. ## need to DL, etc
  99. ##
  100. BASEURL="https://archive.apache.org/dist/yetus/${HADOOP_YETUS_VERSION}/"
  101. TARBALL="yetus-${HADOOP_YETUS_VERSION}-bin.tar"
  102. GPGBIN=$(command -v gpg)
  103. CURLBIN=$(command -v curl)
  104. if ! pushd "${HADOOP_PATCHPROCESS}" >/dev/null; then
  105. yetus_error "ERROR: yetus-dl: Cannot pushd to ${HADOOP_PATCHPROCESS}"
  106. exit 1
  107. fi
  108. if [[ -n "${CURLBIN}" ]]; then
  109. if ! "${CURLBIN}" -f -s -L -O "${BASEURL}/${TARBALL}.gz"; then
  110. yetus_error "ERROR: yetus-dl: unable to download ${BASEURL}/${TARBALL}.gz"
  111. exit 1
  112. fi
  113. else
  114. yetus_error "ERROR: yetus-dl requires curl."
  115. exit 1
  116. fi
  117. if [[ -n "${GPGBIN}" ]]; then
  118. if ! mkdir -p .gpg; then
  119. yetus_error "ERROR: yetus-dl: Unable to create ${HADOOP_PATCHPROCESS}/.gpg"
  120. exit 1
  121. fi
  122. if ! chmod -R 700 .gpg; then
  123. yetus_error "ERROR: yetus-dl: Unable to chmod ${HADOOP_PATCHPROCESS}/.gpg"
  124. exit 1
  125. fi
  126. if ! "${CURLBIN}" -s -L -o KEYS_YETUS https://dist.apache.org/repos/dist/release/yetus/KEYS; then
  127. yetus_error "ERROR: yetus-dl: unable to fetch https://dist.apache.org/repos/dist/release/yetus/KEYS"
  128. exit 1
  129. fi
  130. if ! "${CURLBIN}" -s -L -O "${BASEURL}/${TARBALL}.gz.asc"; then
  131. yetus_error "ERROR: yetus-dl: unable to fetch ${BASEURL}/${TARBALL}.gz.asc"
  132. exit 1
  133. fi
  134. if ! "${GPGBIN}" --homedir "${HADOOP_PATCHPROCESS}/.gpg" --import "${HADOOP_PATCHPROCESS}/KEYS_YETUS" >/dev/null 2>&1; then
  135. yetus_error "ERROR: yetus-dl: gpg unable to import ${HADOOP_PATCHPROCESS}/KEYS_YETUS"
  136. exit 1
  137. fi
  138. if ! "${GPGBIN}" --homedir "${HADOOP_PATCHPROCESS}/.gpg" --verify "${TARBALL}.gz.asc" >/dev/null 2>&1; then
  139. yetus_error "ERROR: yetus-dl: gpg verify of tarball in ${HADOOP_PATCHPROCESS} failed"
  140. exit 1
  141. fi
  142. fi
  143. if ! (gunzip -c "${TARBALL}.gz" | tar xpf -); then
  144. yetus_error "ERROR: ${TARBALL}.gz is corrupt. Investigate and then remove ${HADOOP_PATCHPROCESS} to try again."
  145. exit 1
  146. fi
  147. if [[ -x "${HADOOP_PATCHPROCESS}/yetus-${HADOOP_YETUS_VERSION}/bin/${WANTED}" ]]; then
  148. popd >/dev/null
  149. exec "${HADOOP_PATCHPROCESS}/yetus-${HADOOP_YETUS_VERSION}/bin/${WANTED}" "${ARGV[@]}"
  150. fi
  151. ##
  152. ## give up
  153. ##
  154. yetus_error "ERROR: ${WANTED} is not part of Apache Yetus ${HADOOP_YETUS_VERSION}"
  155. exit 1