yetus-wrapper 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. function version_ge()
  65. {
  66. test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1";
  67. }
  68. WANTED="$1"
  69. shift
  70. ARGV=("$@")
  71. HADOOP_YETUS_VERSION=${HADOOP_YETUS_VERSION:-0.14.1}
  72. BIN=$(yetus_abs "${BASH_SOURCE-$0}")
  73. BINDIR=$(dirname "${BIN}")
  74. ## HADOOP_YETUS_VERSION >= 0.9.0 the tarball named with apache-yetus prefix
  75. if version_ge "${HADOOP_YETUS_VERSION}" "0.9.0"; then
  76. YETUS_PREFIX=apache-yetus
  77. else
  78. YETUS_PREFIX=yetus
  79. fi
  80. ###
  81. ### if YETUS_HOME is set, then try to use it
  82. ###
  83. if [[ -n "${YETUS_HOME}" && -x "${YETUS_HOME}/bin/${WANTED}" ]]; then
  84. exec "${YETUS_HOME}/bin/${WANTED}" "${ARGV[@]}"
  85. fi
  86. #
  87. # this directory is ignored by git and maven
  88. #
  89. HADOOP_PATCHPROCESS=${HADOOP_PATCHPROCESS:-"${BINDIR}/../../patchprocess"}
  90. if [[ ! -d "${HADOOP_PATCHPROCESS}" ]]; then
  91. mkdir -p "${HADOOP_PATCHPROCESS}"
  92. fi
  93. mytmpdir=$(yetus_abs "${HADOOP_PATCHPROCESS}")
  94. ret=$?
  95. if [[ ${ret} != 0 ]]; then
  96. yetus_error "yetus-dl: Unable to cwd to ${HADOOP_PATCHPROCESS}"
  97. exit 1
  98. fi
  99. HADOOP_PATCHPROCESS=${mytmpdir}
  100. ##
  101. ## if we've already DL'd it, then short cut
  102. ##
  103. if [[ -x "${HADOOP_PATCHPROCESS}/${YETUS_PREFIX}-${HADOOP_YETUS_VERSION}/bin/${WANTED}" ]]; then
  104. exec "${HADOOP_PATCHPROCESS}/${YETUS_PREFIX}-${HADOOP_YETUS_VERSION}/bin/${WANTED}" "${ARGV[@]}"
  105. fi
  106. ##
  107. ## need to DL, etc
  108. ##
  109. BASEURL="https://downloads.apache.org/yetus/${HADOOP_YETUS_VERSION}/"
  110. TARBALL="${YETUS_PREFIX}-${HADOOP_YETUS_VERSION}-bin.tar"
  111. GPGBIN=$(command -v gpg)
  112. CURLBIN=$(command -v curl)
  113. if ! pushd "${HADOOP_PATCHPROCESS}" >/dev/null; then
  114. yetus_error "ERROR: yetus-dl: Cannot pushd to ${HADOOP_PATCHPROCESS}"
  115. exit 1
  116. fi
  117. if [[ -n "${CURLBIN}" ]]; then
  118. if ! "${CURLBIN}" -f -s -L -O "${BASEURL}/${TARBALL}.gz"; then
  119. yetus_error "ERROR: yetus-dl: unable to download ${BASEURL}/${TARBALL}.gz"
  120. exit 1
  121. fi
  122. else
  123. yetus_error "ERROR: yetus-dl requires curl."
  124. exit 1
  125. fi
  126. if [[ -n "${GPGBIN}" && ! "${HADOOP_SKIP_YETUS_VERIFICATION}" = true ]]; then
  127. if ! mkdir -p .gpg; then
  128. yetus_error "ERROR: yetus-dl: Unable to create ${HADOOP_PATCHPROCESS}/.gpg"
  129. exit 1
  130. fi
  131. if ! chmod -R 700 .gpg; then
  132. yetus_error "ERROR: yetus-dl: Unable to chmod ${HADOOP_PATCHPROCESS}/.gpg"
  133. exit 1
  134. fi
  135. if ! "${CURLBIN}" -s -L -o KEYS_YETUS https://dist.apache.org/repos/dist/release/yetus/KEYS; then
  136. yetus_error "ERROR: yetus-dl: unable to fetch https://dist.apache.org/repos/dist/release/yetus/KEYS"
  137. exit 1
  138. fi
  139. if ! "${CURLBIN}" -s -L -O "${BASEURL}/${TARBALL}.gz.asc"; then
  140. yetus_error "ERROR: yetus-dl: unable to fetch ${BASEURL}/${TARBALL}.gz.asc"
  141. exit 1
  142. fi
  143. if ! "${GPGBIN}" --homedir "${HADOOP_PATCHPROCESS}/.gpg" --import "${HADOOP_PATCHPROCESS}/KEYS_YETUS" >/dev/null 2>&1; then
  144. yetus_error "ERROR: yetus-dl: gpg unable to import ${HADOOP_PATCHPROCESS}/KEYS_YETUS"
  145. exit 1
  146. fi
  147. if ! "${GPGBIN}" --homedir "${HADOOP_PATCHPROCESS}/.gpg" --verify "${TARBALL}.gz.asc" >/dev/null 2>&1; then
  148. yetus_error "ERROR: yetus-dl: gpg verify of tarball in ${HADOOP_PATCHPROCESS} failed"
  149. exit 1
  150. fi
  151. fi
  152. if [[ "$IS_WINDOWS" && "$IS_WINDOWS" == 1 ]]; then
  153. gunzip -c "${TARBALL}.gz" | tar xpf -
  154. # One of the entries in the Yetus tarball unzips a symlink qbt.sh.
  155. # The symlink creation fails on Windows, unless this CI is run as Admin or Developer mode is
  156. # enabled.
  157. # Thus, we create the qbt.sh symlink ourselves and move it to the target.
  158. YETUS_PRECOMMIT_DIR="${YETUS_PREFIX}-${HADOOP_YETUS_VERSION}/lib/precommit"
  159. ln -s "${YETUS_PRECOMMIT_DIR}/test-patch.sh" qbt.sh
  160. mv qbt.sh "${YETUS_PRECOMMIT_DIR}"
  161. elif ! (gunzip -c "${TARBALL}.gz" | tar xpf -); then
  162. yetus_error "ERROR: ${TARBALL}.gz is corrupt. Investigate and then remove ${HADOOP_PATCHPROCESS} to try again."
  163. exit 1
  164. fi
  165. if [[ -x "${HADOOP_PATCHPROCESS}/${YETUS_PREFIX}-${HADOOP_YETUS_VERSION}/bin/${WANTED}" ]]; then
  166. popd >/dev/null
  167. exec "${HADOOP_PATCHPROCESS}/${YETUS_PREFIX}-${HADOOP_YETUS_VERSION}/bin/${WANTED}" "${ARGV[@]}"
  168. fi
  169. ##
  170. ## give up
  171. ##
  172. yetus_error "ERROR: ${WANTED} is not part of Apache Yetus ${HADOOP_YETUS_VERSION}"
  173. exit 1