Skip to content

Instantly share code, notes, and snippets.

@ceteri
Created Jun 4, 2012
Embed
What would you like to do?
#!/bin/bash
set -e -x
# Usage:
# --user-home - an alternative user to install into, default /home/hadoop
# --tmpdir - an alternative temporary directory, default TMPDIR or /tmp if not set
# --no-screen - do not install screen, screen is installed by default on the master as a convenience
# --latest - url to text file referencing the latest version
# --no-bash - do not update .bashrc
LATEST=http://@location@/multitool/2.0/latest.txt
case "`uname`" in
Darwin)
USER_HOME=/Users/$USER;;
*)
USER_HOME=/home/$USER;;
esac
BASH_PROFILE=.bashrc
INSTALL_SCREEN=y
UPDATE_BASH=y
IS_MASTER=false
if [ -f /mnt/var/lib/info/instance.json ]
then
IS_MASTER=`cat /mnt/var/lib/info/instance.json | tr -d '\n ' | sed -n 's|.*\"isMaster\":\([^,]*\).*|\1|p'`
USER_HOME=/home/hadoop
fi
[ -n $TMPDIR ] && TMPDIR=/tmp
error_msg () # msg
{
echo 1>&2 "Error: $1"
}
error_exit () # <msg> <cod>
{
error_msg "$1"
exit ${2:-1}
}
while [ $# -gt 0 ]
do
case "$1" in
--latest)
shift
LATEST=$1
;;
--user-home)
shift
USER_HOME=$1
;;
--tmpdir)
shift
TMPDIR=$1
;;
--no-screen)
INSTALL_SCREEN=
;;
--no-bash)
UPDATE_BASH=
;;
-*)
# do not exit out, just note failure
error_msg "unrecognized option: $1"
;;
*)
break;
;;
esac
shift
done
if [ "$IS_MASTER" = "false" ]; then
exit 0
fi
MT_HOME=$USER_HOME/.multitool
[ -d $MT_HOME ] && UPDATE_BASH=
REDIR=$TMPDIR/latest
ARCHIVE=$TMPDIR/archive.tgz
# find latest Multitool
wget -S -T 10 -t 5 $LATEST -O $REDIR
# download latest
wget -S -T 10 -t 5 -i $REDIR -O $ARCHIVE
# unpack into /home/hadoop/<multitool>
TMPFILE=`mktemp -d -t multitool.XXXXX`
[ -d $MT_HOME ] && mv $MT_HOME $TMPFILE
tar -xzf $ARCHIVE -C $USER_HOME
mv $USER_HOME/multitool $MT_HOME # comes archived as multitool
# update classpath on user hadoop to include multitool jar
# 'cause gradle sucks and can't set file permissions during a copy
chmod a+x $MT_HOME/bin/*
mv $REDIR $MT_HOME/bin/.current
echo "$LATEST" > $MT_HOME/bin/.latest
MT_JAR=`find $MT_HOME -name '*.jar' -type f`
(cd $MT_HOME; ln -f -s $MT_JAR multitool.jar)
if [ -n "$UPDATE_BASH" ]; then
cat >> $USER_HOME/$BASH_PROFILE <<- EOF
# Multitool - Concurrent, Inc.
# http://www.concurrentinc.com/
export MT_HOME=$MT_HOME
# add Multitool to PATH
export PATH=\$PATH:\$MT_HOME/bin
# using symlink to support selfupdate from multitool shell script
export HADOOP_CLASSPATH=\$MT_HOME/multitool.jar:\$HADOOP_CLASSPATH
EOF
fi
if [ "$IS_MASTER" = "true" ]; then
[ -n "$INSTALL_SCREEN" ] && sudo apt-get --force-yes install screen -y
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment