#!/bin/sh

# ifdown - bring a network interface down

if [ $# -ne 1 ] ; then
	echo "usage: $0 <interface>"
	exit 1
fi

DEVICE=$1

# if device isn't up, then don't do anything
if [ -z "`ifconfig -a | sed -ne "s/$DEVICE//p"`" ] ; then
	exit 0
fi

# check if config file is there, so we know how to bring it down
if [ ! -f @CONFIG_DIR@/net/$DEVICE ] ; then
	echo "No configuration for $DEVICE"
	exit 1
fi

. @CONFIG_DIR@/net/$DEVICE

# the config file may have changed since the last ifup, so we kill
# the connection with everything we have
[ -f /sbin/pump ] && pump -r -i $DEVICE
sleep 1

[ -f /sbin/pump ] && killall pump
[ -f /sbin/dhclient ] && killall dhclient

sleep 1
ifconfig $DEVICE down

exit 0
