#!/bin/bash
#
# This wrapper try to remove system's unmodified environment variables
# and propagate user environments on the nodes.
#
# This script is licence under the same licence as OAR program
#  GNU GENERAL PUBLIC LICENSE
#  http://oar.imag.fr/
#
# 1.0 Nicolas Capit  (initial version for PATH and LD_LIBRARY_PATH)
# 1.1 Patrick Begou  (all the environment excepted... that could make problems!)
# 1.2 Gabriel Moreau (format and licence)
#

HOST=$1
shift

MYENV=$( env \
   | grep "^[ABCDEFGHIJKLMNOPQRSTUVWXYZ]" \
   | egrep -v "^USER=|^TERM=|^OAR|^SGE_|^LS_COLORS=\
      |^ENV=|^BASH_ENV=|^HOSTNAME=|^LOGNAME=|^MAIL=\
      |^MANPATH=|^OMPI_MCA_plm_rsh_agent=|^PWD=\
      |^SHELL=|^SSH_|^SUDO_COMMAND=|^HOME=|^DISPLAY=\
      |^SHLVL=" \
   | sort \
   | sed -e s"/^/export /" \
   | tr [\\\n] [\;] )

exec /opt/oar/current/bin/oarsh $HOST "$MYENV $@"
