#!/bin/sh
#
# Script which sets correct LD_LIBRARY_PATH and calls
# a underlying program
# Copyright 2015 VMware, Inc.  All rights reserved.
#
SCRIPTNAME="$(basename "$0")"
BINNAME="${SCRIPTNAME#vmware-}"
REALNAME="$(readlink -f "$0")"
BINDIR="$(dirname "${REALNAME}")"

APPLIANCE_NAME=$(sed -n -e 's/^CLOUDVM_NAME://p' /etc/vmware/.buildInfo 2>/dev/null)
# Run the update manager utility if we are running in an vCenter Server
# Appliance and update manager binary is being executed.
if [ "${APPLIANCE_NAME}" = "VMware-vCenter-Server-Appliance" ] && \
    [ "${BINNAME}" = "updatemgr" ]; then
    # Re-register with VC in case our cert or ports have changed
    PYTHONPATH=/usr/lib/vmware/site-packages ${BINDIR}/refreshCerts-utility.py > /dev/null 2>&1
    if [ $? -ne 0 ]; then
    exit 1
    fi
fi

export LD_LIBRARY_PATH="${BINDIR}/../lib:${LD_LIBRARY_PATH}"
exec "${BINDIR}/${BINNAME}" "$@"
