#!/bin/bash
#
# This wrapper try to remove system's unmodified environment variables and propagate user environments on the nodes.
#
# version 1.0 by Nicolas Capit (initial version for PATH and LD_LIBRARY_PATH)
# version 1.1 by Patrick Begou (All the environment excepted.... that could make problems!)
#

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 $@"
