#!/bin/sh
#
# call the notification tool if a network interface appear or disappear
#
# link this file to
#   /etc/NetworkManager/dispatcher.d
#   /etc/network/if-up.d
#   /etc/network/if-down.d
# ---------------------------------------------------------------------
if test $1 && test $2; then
    # We were called from 'network manager' or 'wicd'
    WICD="wired"

    if [ ${1} = $WICD ] && [ ${2} = $WICD ]; then
        # We were called from 'wicd'
        WICD_CONFIG="/etc/wicd/manager-settings.conf"
        INTERFACE=`cat $WICD_CONFIG | awk '/wired_interface/ && /^[w]/ {print $3}'`

    if [ ${3} = $WICD ]; then
        ACTION="down"
    else
        ACTION="up"
    fi

    /usr/bin/ueyenotify -F nmd -i ${INTERFACE} -a ${ACTION}
    
    else
        # We were called from 'network manager'
        INTERFACE=$1
        ACTION=$2
        if [ ${ACTION} = "down" ] || [ ${ACTION} = "up" ]; then
            /usr/bin/ueyenotify -F nmd -i ${INTERFACE} -a ${ACTION}
        fi
    fi

else
    # We were called from 'if-*.d' script
    /usr/bin/ueyenotify -F eth
fi
