#!/bin/sh

########################################################################
# DO NOT modify this file directly as it will be overwritten the next
# time the VMware Tools are installed. 
########################################################################

echo `date` ": Executing '$0'"
echo

find_initdir() {
    for dir in "/etc/init.d" "/sbin/init.d" "/etc" "/etc/rc.d" ; do
        if [ -d "$dir/rc0.d" ] &&
	    [ -d "$dir/rc1.d" ] &&
	    [ -d "$dir/rc2.d" ] &&
	    [ -d "$dir/rc3.d" ] &&
	    [ -d "$dir/rc4.d" ] &&
	    [ -d "$dir/rc5.d" ] &&
	    [ -d "$dir/rc6.d" ]; then
	    if [ -d "$dir/init.d" ]; then
		echo "$dir/init.d"
	    else
		echo "$dir"
	    fi
	    return
        fi
    done

    echo "error"
}

save_active_NIC_list() {
    ifconfig_path=`which ifconfig 2>/dev/null`
    if [ $? ]; then
       "$ifconfig_path" | grep '^[^[:space:]]' | awk '{ print $1 }' > /var/run/vmware-active-nics
    fi
}

#
# main
#
save_active_NIC_list

initdir=`find_initdir`
if [ "$initdir" != "error" ]; then
   if [ -x "$initdir/network" ]; then
      network="$initdir/network"
   elif [ -x "$initdir/networking" ]; then
      network="$initdir/networking"
   else
      echo \"$initdir/network\" or \"$initdir/networking\" not found!
      status=1
   fi
   if [ -n "$network" ]; then
      "$network" stop
      # If the network is down, this will fail but that's not a good reason
      # to prevent the suspend.
      status=0
   fi
else
   echo initdir not found
   status=1
fi

exit "$status"
