#!/bin/sh
#
# by Andrew McMillan, Catalyst IT Ltd, (c) 2001 licensed
# for use under the GPL version 2
#

# Turn on execution tracing, for debugging...
[ "$DEBUGWHEREAMI" = "1" ] && set -o xtrace

ifconfig $1 up

#
# Use apparently more reliable mii-tool...
if [ -x /sbin/mii-tool ] ; then
  /sbin/mii-tool $1 2>&1 | grep "link ok" >/dev/null && exit 0

  # Don't exit on failure unless we confirm that mii-tool was supported
  # since it won't work on many modern Gb cards...
  /sbin/mii-tool $1 2>&1 | grep "Operation not supported" >/dev/null || exit 1
fi

if [ -x /usr/sbin/ethtool ] ; then
  # Fall back to ethtool, which can give false positives on this
  /usr/sbin/ethtool $1 2>&1 | grep "Link detected: yes" >/dev/null && exit 0
fi


# Interface is not connected - bring it down to remove it from
# routing table
ifconfig $1 down

exit 1

