dist-tools-hooks-maker 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #!/usr/bin/env bash
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. VERSION=${1:-3.0.0-SNAPSHOT}
  19. TARGETDIR=${2:-/tmp/target}
  20. TOOLSDIR=${3:-/tmp/tools}
  21. function getfilename
  22. {
  23. declare module=$1
  24. declare modtype=$2
  25. if [[ ${modtype} = builtin ]]; then
  26. echo "${TARGETDIR}/hadoop-${VERSION}/libexec/tools/${module}.sh"
  27. else
  28. echo "${TARGETDIR}/hadoop-${VERSION}/libexec/shellprofile.d/${module}.sh"
  29. fi
  30. }
  31. function header
  32. {
  33. declare fn=$1
  34. cat >>"${fn}" <<-'TOKEN'
  35. #!/usr/bin/env bash
  36. #
  37. # Licensed to the Apache Software Foundation (ASF) under one or more
  38. # contributor license agreements. See the NOTICE file distributed with
  39. # this work for additional information regarding copyright ownership.
  40. # The ASF licenses this file to You under the Apache License, Version 2.0
  41. # (the "License"); you may not use this file except in compliance with
  42. # the License. You may obtain a copy of the License at
  43. #
  44. # http://www.apache.org/licenses/LICENSE-2.0
  45. #
  46. # Unless required by applicable law or agreed to in writing, software
  47. # distributed under the License is distributed on an "AS IS" BASIS,
  48. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  49. # See the License for the specific language governing permissions and
  50. # limitations under the License.
  51. #
  52. #
  53. #
  54. # IMPORTANT: This file is automatically generated by hadoop-dist at
  55. # -Pdist time.
  56. #
  57. #
  58. TOKEN
  59. }
  60. function optional_prologue
  61. {
  62. declare fn=$1
  63. declare module=$2
  64. if [[ -z "${OPTMODS}" ]]; then
  65. OPTMODS=${module}
  66. else
  67. OPTMODS="${OPTMODS},${module}"
  68. fi
  69. {
  70. echo "if hadoop_verify_entry HADOOP_TOOLS_OPTIONS \"${module}\"; then"
  71. echo " hadoop_add_profile \"${module}\""
  72. echo "fi"
  73. echo ""
  74. echo "function _${module}_hadoop_classpath"
  75. echo "{"
  76. } >> "${fn}"
  77. }
  78. function builtin_prologue
  79. {
  80. declare fn=$1
  81. declare module=$2
  82. {
  83. echo ""
  84. echo "function hadoop_classpath_tools_${module}"
  85. echo "{"
  86. } >> "${fn}"
  87. }
  88. function dependencywork
  89. {
  90. declare fn=$1
  91. declare module=$2
  92. declare depfn=$3
  93. declare depline
  94. declare jarname
  95. while read -r depline; do
  96. jarname=$(echo "${depline}" | awk -F: '{print $2"-"$4".jar"}')
  97. if [[ -f "${TARGETDIR}/hadoop-${VERSION}/share/hadoop/tools/lib/${jarname}" ]]; then
  98. {
  99. echo " if [[ -f \"\${HADOOP_TOOLS_HOME}/\${HADOOP_TOOLS_LIB_JARS_DIR}/${jarname}\" ]]; then"
  100. echo " hadoop_add_classpath \"\${HADOOP_TOOLS_HOME}/\${HADOOP_TOOLS_LIB_JARS_DIR}/${jarname}\""
  101. echo " fi"
  102. } >> "${fn}"
  103. elif [[ -f "${TARGETDIR}/hadoop-${VERSION}/share/hadoop/common/${jarname}"
  104. || -f "${TARGETDIR}/hadoop-${VERSION}/share/hadoop/common/lib/${jarname}" ]]; then
  105. true
  106. else
  107. echo "ERROR: ${module} has missing dependencies: ${jarname}"
  108. fi
  109. done < <(grep compile "${depfn}")
  110. {
  111. echo " hadoop_add_classpath \"\${HADOOP_TOOLS_HOME}/\${HADOOP_TOOLS_LIB_JARS_DIR}/${module}-${VERSION}.jar\""
  112. echo "}"
  113. echo ""
  114. } >> "${fn}"
  115. }
  116. function document_optionals
  117. {
  118. echo "Rewriting ${TARGETDIR}/hadoop-${VERSION}/etc/hadoop/hadoop-env.sh"
  119. sed -e "s^@@@HADOOP_OPTIONAL_TOOLS@@@^${OPTMODS}^" \
  120. "${TARGETDIR}/hadoop-${VERSION}/etc/hadoop/hadoop-env.sh" \
  121. > "${TARGETDIR}/hadoop-${VERSION}/etc/hadoop/hadoop-env.sh.new"
  122. mv "${TARGETDIR}/hadoop-${VERSION}/etc/hadoop/hadoop-env.sh.new" \
  123. "${TARGETDIR}/hadoop-${VERSION}/etc/hadoop/hadoop-env.sh"
  124. }
  125. function process
  126. {
  127. declare fn
  128. declare basefn
  129. declare modtype
  130. declare module
  131. declare newfile
  132. declare newdir
  133. while read -r fn; do
  134. basefn=${fn##*/}
  135. module=$(echo "${basefn}" | cut -f1 -d.)
  136. modtype=$(echo "${basefn}" | cut -f2 -d.)
  137. modtype=${modtype##tools-}
  138. newfile=$(getfilename "${module}" "${modtype}")
  139. newdir=$(dirname "${newfile}")
  140. mkdir -p "${newdir}"
  141. if [[ -f "${newfile}" ]]; then
  142. rm "${newfile}"
  143. fi
  144. touch "${newfile}"
  145. header "${newfile}" "${module}"
  146. "${modtype}_prologue" "${newfile}" "${module}"
  147. dependencywork "${newfile}" "${module}" "${fn}"
  148. chmod a+rx "${newfile}"
  149. done < <(find "${TOOLSDIR}" -name '*.tools-builtin.txt' -o -name '*.tools-optional.txt')
  150. document_optionals
  151. }
  152. process