#!/usr/bin/env bash
#
# Copyright 2005-2008, 2020 VMware, Inc.  All rights reserved.
#
# Wrapper for the real 'vmware' 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

export PRODUCT_NAME="VMware Workstation"
source /etc/conf.d/vmware
libdir="$LIBDIR"/vmware

# The new Ubuntu menu system "steals" our menu out of the UI, which causes problems
# with fullscreening.  These variables disable that in various unity versions.
export APPMENU_DISPLAY_BOTH=1
export UBUNTU_MENUPROXY=0

# bug-buddy breaks logging
export GNOME_DISABLE_CRASH_DIALOG=1

vmware_module_exists()
{
   modalias=$1
   /sbin/modprobe -n $modalias > /dev/null 2>&1
}

# If there are command line arguments like -version, launch the binary without
# checking configuration state or running the module updater.
if echo "$1" | grep -q "^-"; then
   exec "$libdir"/bin/"vmware" "$@"
fi

# Only run the GUI if DISPLAY is set.
if [ -z "$DISPLAY" ]; then
   echo "DISPLAY is not set, unable to open the $PRODUCT_NAME user interface."
   exit 1
fi

# Required by vmware-modconfig-console
export VMWARE_INSTALLER=$BINDIR/vmware-installer

if vmware_module_exists 'vmmon' && vmware_module_exists 'vmnet'; then
   exec "$libdir"/bin/"vmware" "$@"
elif true ||
   vmware_module_exists 'vmmon'; then
   exec "$libdir"/bin/"vmware" "$@"
fi

exit 1
