123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #!/usr/bin/env bash
- #
- # Licensed to the Apache Software Foundation (ASF) under one or more
- # contributor license agreements. See the NOTICE file distributed with
- # this work for additional information regarding copyright ownership.
- # The ASF licenses this file to You under the Apache License, Version 2.0
- # (the "License"); you may not use this file except in compliance with
- # the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- #
- VERSION=${1:-3.0.0-SNAPSHOT}
- TARGETDIR=${2:-/tmp/target}
- TOOLSDIR=${3:-/tmp/tools}
- function getfilename
- {
- declare module=$1
- declare modtype=$2
- if [[ ${modtype} = builtin ]]; then
- echo "${TARGETDIR}/hadoop-${VERSION}/libexec/tools/${module}.sh"
- else
- echo "${TARGETDIR}/hadoop-${VERSION}/libexec/shellprofile.d/${module}.sh"
- fi
- }
- function header
- {
- declare fn=$1
- cat >>"${fn}" <<-'TOKEN'
- #!/usr/bin/env bash
- #
- # Licensed to the Apache Software Foundation (ASF) under one or more
- # contributor license agreements. See the NOTICE file distributed with
- # this work for additional information regarding copyright ownership.
- # The ASF licenses this file to You under the Apache License, Version 2.0
- # (the "License"); you may not use this file except in compliance with
- # the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- #
- #
- #
- # IMPORTANT: This file is automatically generated by hadoop-dist at
- # -Pdist time.
- #
- #
- TOKEN
- }
- function optional_prologue
- {
- declare fn=$1
- declare module=$2
- if [[ -z "${OPTMODS}" ]]; then
- OPTMODS=${module}
- else
- OPTMODS="${OPTMODS},${module}"
- fi
- {
- echo "if hadoop_verify_entry HADOOP_TOOLS_OPTIONS \"${module}\"; then"
- echo " hadoop_add_profile \"${module}\""
- echo "fi"
- echo ""
- echo "function _${module}_hadoop_classpath"
- echo "{"
- } >> "${fn}"
- }
- function builtin_prologue
- {
- declare fn=$1
- declare module=$2
- {
- echo ""
- echo "function hadoop_classpath_tools_${module}"
- echo "{"
- } >> "${fn}"
- }
- function dependencywork
- {
- declare fn=$1
- declare module=$2
- declare depfn=$3
- declare depline
- declare jarname
- while read -r depline; do
- jarname=$(echo "${depline}" | awk -F: '{print $2"-"$4".jar"}')
- if [[ -f "${TARGETDIR}/hadoop-${VERSION}/share/hadoop/tools/lib/${jarname}" ]]; then
- {
- echo " if [[ -f \"\${HADOOP_TOOLS_HOME}/\${HADOOP_TOOLS_LIB_JARS_DIR}/${jarname}\" ]]; then"
- echo " hadoop_add_classpath \"\${HADOOP_TOOLS_HOME}/\${HADOOP_TOOLS_LIB_JARS_DIR}/${jarname}\""
- echo " fi"
- } >> "${fn}"
- elif [[ -f "${TARGETDIR}/hadoop-${VERSION}/share/hadoop/common/${jarname}"
- || -f "${TARGETDIR}/hadoop-${VERSION}/share/hadoop/common/lib/${jarname}" ]]; then
- true
- else
- echo "ERROR: ${module} has missing dependencies: ${jarname}"
- fi
- done < <(grep compile "${depfn}")
- {
- echo " hadoop_add_classpath \"\${HADOOP_TOOLS_HOME}/\${HADOOP_TOOLS_LIB_JARS_DIR}/${module}-${VERSION}.jar\""
- echo "}"
- echo ""
- } >> "${fn}"
- }
- function document_optionals
- {
- echo "Rewriting ${TARGETDIR}/hadoop-${VERSION}/etc/hadoop/hadoop-env.sh"
- sed -e "s^@@@HADOOP_OPTIONAL_TOOLS@@@^${OPTMODS}^" \
- "${TARGETDIR}/hadoop-${VERSION}/etc/hadoop/hadoop-env.sh" \
- > "${TARGETDIR}/hadoop-${VERSION}/etc/hadoop/hadoop-env.sh.new"
- mv "${TARGETDIR}/hadoop-${VERSION}/etc/hadoop/hadoop-env.sh.new" \
- "${TARGETDIR}/hadoop-${VERSION}/etc/hadoop/hadoop-env.sh"
- }
- function process
- {
- declare fn
- declare basefn
- declare modtype
- declare module
- declare newfile
- declare newdir
- while read -r fn; do
- basefn=${fn##*/}
- module=$(echo "${basefn}" | cut -f1 -d.)
- modtype=$(echo "${basefn}" | cut -f2 -d.)
- modtype=${modtype##tools-}
- newfile=$(getfilename "${module}" "${modtype}")
- newdir=$(dirname "${newfile}")
- mkdir -p "${newdir}"
- if [[ -f "${newfile}" ]]; then
- rm "${newfile}"
- fi
- touch "${newfile}"
- header "${newfile}" "${module}"
- "${modtype}_prologue" "${newfile}" "${module}"
- dependencywork "${newfile}" "${module}" "${fn}"
- chmod a+rx "${newfile}"
- done < <(find "${TOOLSDIR}" -name '*.tools-builtin.txt' -o -name '*.tools-optional.txt')
- document_optionals
- }
- process
|