#!/bin/sh

if [ $# -lt 7 ]
then
	echo "usage: $0 <glexec> <proxy> <sandbox> " \
             "<wrapper> <stdin> <stdout> <stderr> <cmd> [<arg> ...]" >&2
	exit 1
fi

GLEXEC="$1"
PROXY="$2"
SANDBOX="$3"

shift 3

# use glexec to start a script that
#   - changes into the right working directory
#   - execs the wrapper, which will take care of the rest
#
SH=`readlink -f /bin/sh`
GLEXEC_CLIENT_CERT="$SANDBOX.condor/$PROXY"
export GLEXEC_CLIENT_CERT
# prevent glexec from creating a proxy in /tmp that is not cleaned up
GLEXEC_TARGET_PROXY="$SANDBOX/$PROXY"
export GLEXEC_TARGET_PROXY
exec "$GLEXEC" "$SH" -c "cd \"$SANDBOX\" && exec \"\$@\"" cd-and-exec "$@"
