#!/usr/bin/env bash
#
# Copyright 2005-2008 VMware, Inc.  All rights reserved.
#
# Wrapper for the real binary. Ensure that the binary will find all
# the shared libraries it needs. If a shared library is not available
# from any of the standard system-wide locations, we provide it from
# the location where the VMware software is installed.
#

set -e

ETCDIR=/etc/vmware
. $ETCDIR/bootstrap

VMISETCDIR=/etc/vmware-installer
. $VMISETCDIR/bootstrap

libdir="$LIBDIR"/vmware

export VMWARE_INSTALLER

args=""
uiType=""
useConsole=0

# Process the Args first and look for --console.  If its there,
# then remove it and set uiType=-console
for i in "$@"; do
   if [ "$i" = '--console' ]; then
      useConsole=1
   else
      args="$args $i"
   fi
done

if [ -z "$DISPLAY" ] || [ "$useConsole" = 1 ]; then
   uiType="-console"
else
   args="--launcher=$0 $args"
fi

# RHEL doesn't include /sbin in PATH when su'ed which is needed for modinfo
# XXX: check for it before adding it
export PATH="/sbin:${PATH}"
exec "$libdir"/bin/vmware-modconfig$uiType $args
