#!/bin/bash # XXX: This is in post-install.d, instead of install.d, because the # hadoop RPM claims ownership of files owned by the filesystem RPM, # such as /usr and /bin, and installing hadoop then updating # filesystem results in a failure. This can be moved to install.d when # HADOOP-9777 is resolved. # https://issues.apache.org/jira/browse/HADOOP-9777 function download_hadoop_package { echo "Hadoop version $DIB_HADOOP_VERSION will be injected into image. Starting the download" install-packages wget wget -P $tmp_dir "http://archive.apache.org/dist/hadoop/core/hadoop-$DIB_HADOOP_VERSION/$package" if [ $? -ne 0 ]; then echo -e "Could not find Hadoop version $DIB_HADOOP_VERSION.\nAborting" exit 1 fi } function find_java_home { JAVA_HOME=$(find $TARGET_ROOT$JAVA_TARGET_LOCATION/ -maxdepth 1 -name "jdk*") if [ -z "$JAVA_HOME" ]; then case "$distro" in Ubuntu ) JAVA_HOME=$(readlink -e /usr/bin/java | sed "s:bin/java::") ;; Fedora | RedHatEnterpriseServer | CentOS ) JAVA_HOME=$(rpm --eval '%{?java_home}') ;; esac fi } function install_hadoop_v1 { case "$distro" in Ubuntu ) package="hadoop_$DIB_HADOOP_VERSION-1_x86_64.deb" ;; Fedora | RedHatEnterpriseServer | CentOS ) package="hadoop-$DIB_HADOOP_VERSION-1.x86_64.rpm" ;; esac download_hadoop_package case "$distro" in Ubuntu ) dpkg -i $tmp_dir/$package ;; Fedora | RedHatEnterpriseServer | CentOS ) if [ $(lsb_release -rs) -ge '19' ]; then rpm -i $tmp_dir/$package --relocate /usr=/usr --replacefiles else rpm -ivh --replacefiles $tmp_dir/$package fi chmod 755 /usr/sbin/start-* chmod 755 /usr/sbin/stop-* chmod 755 /usr/sbin/slaves.sh chmod 755 /usr/sbin/update-hadoop-env.sh ;; esac rm -r $tmp_dir echo "Pre-configuring Hadoop" find_java_home cat >> /home/hadoop/.bashrc <> /etc/profile.d/hadoop.sh <