#!/usr/bin/env bash
#
# Copyright 2005-2008,2019 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

libdir="$LIBDIR"/vmware
. "$libdir"/scripts/util.sh

load_settings "$libdir"

# one of either su or sudo
rootMethod="$vmdb_gksu_rootMethod"

envSettings=
if [ "$rootMethod" = "sudo" ]; then
   passMessage="Please enter your password to proceed."
elif [ "$rootMethod" = "su" ]; then
   passMessage="Please enter the root password to proceed."
else
   echo "root access method not set"
   exit 1
fi

# Allow for a custom message passed in via environment variable.
if [ -n "$VM_GKSU_MESSAGE" ]; then
   message="$VM_GKSU_MESSAGE

$passMessage"
else
   message="$passMessage"
fi

VMWARE_GKSU_USER=`id -unr`
export VMWARE_GKSU_USER

exec "$libdir"/bin/vmware-gksu --$rootMethod-mode "--message=$message" "$@"

exit 1
