#!/bin/bash
#
# Copyright 2017 VMware, Inc.  All rights reserved.
#
# This script implement the lib dependency checking function of installer
#

longname_smartcard="VMware Horizon Smart Card"
longname_rtav="VMware Horizon Real-Time Audio-Video"
longname_cdr="VMware Horizon Client Drive Redirection"
longname_mmr="VMware Horizon Multimedia Redirection (MMR)"
longname_pcoip="VMware Horizon PCoIP"
longname_usb="VMware Horizon USB Redirection"
longname_mediaprovider="VMware Horizon(R) Virtualization Pack for Skype for Business"
longname_client="VMware Horizon Client"

# TODO: make this map related with vmis scan file list in the future
comp_smartcard="/usr/lib/pcoip/vchan_plugins/libscredirvchanclient.so "
comp_rtav="/usr/lib/pcoip/vchan_plugins/libviewMMDevRedir.so "
comp_cdr="/usr/lib/vmware/view/vdpService/libtsdrClient.so "
comp_mmr="/usr/lib/vmware/view/vdpService/libtsmmrClient.so "

comp_pcoip="/usr/bin/vmware-remotemks "
comp_pcoip+="/usr/bin/vmware-remotemks-container "
comp_pcoip+="/usr/lib/libpcoip_client.so "
comp_pcoip+="/usr/lib/vmware/view/vdpService/librdeSvc.so "
comp_pcoip+="/usr/lib/vmware/view/vdpService/libmksvchanclient.so "
comp_pcoip+="/usr/lib/vmware/libudpProxyLib.so "
comp_pcoip+="/usr/lib/pcoip/vchan_plugins/librdpvcbridge.so "
comp_pcoip+="/usr/lib/pcoip/vchan_plugins/libvdpservice.so "

comp_usb="/usr/lib/vmware/view/usb/libvmware-view-usbd.so "
comp_usb+="/usr/lib/vmware/view/usb/vmware-usbarbitrator "

comp_mediaprovider="/usr/lib/vmware/mediaprovider/libVMWMediaProvider.so "
comp_client="/usr/lib/vmware/view/bin/vmware-view "

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/vmware

for comp in client pcoip smartcard rtav cdr mmr usb mediaprovider
do
   compSuccess=true
   fileMissing=false
   errorOutput=""

   files="comp_"${comp}
   files=${!files}
   for file in $files
   do
      if [ ! -e $file ]; then
         errorOutput+="\t$file: No such file.\n"
         compSuccess=false
         fileMissing=true
         continue
      fi

      result=`ldd $file | grep "not found"`
      if [ "$result"x != ""x ]
      then
         compSuccess=false
         errorOutput+="$result\n"
      fi
   done

   longname="longname_"${comp}
   longname=${!longname}
   if $compSuccess; then
      echo -e "$longname: Success\n"
   else
      echo "$longname: Failed"
      if $fileMissing; then
         echo -e -n "\tThis feature was improperly installed, please re-install"
         echo " it or ignore this message if you won't use it."
      fi
      echo -e "$errorOutput"
   fi
done
