#!/bin/bash
# Shell wrapper for Hadoop scripts in "$HADOOP_HOME/bin"
# as a hadoop user.

CMDNAME=`basename "$0"`

export JAVA_HOME=@java_home@
export HADOOP_HOME=@hadoop_home@

usage() {
  echo "Usage: $CMDNAME [-h|--help] script [args ..]"
  echo "Executes a script in \"$HADOOP_HOME/bin\" as @hadoopuser@ user:"
  ls $HADOOP_HOME/bin
  exit 1
}

if [ $# -eq 0 -o "$1" = "-h" -o "$1" = "--help" ]; then
    usage
fi

SCRIPT="$HADOOP_HOME/bin/$1"
shift

exec sudo -E -u @hadoopuser@ $SCRIPT "$@"
