#!/bin/sh

ifconfig=/sbin/ifconfig

IFACE=eth0
FLAG=
CODE0=0
CODE1=1
CODE2=2
CODE3=3

if test "x$1" = "x-not"; then
	CODE0=1
	CODE1=0
	CODE2=0
	CODE3=0
	shift;
fi

if test -n "$1"; then
	IFACE=$1
fi

IFC="${ifconfig} ${IFACE}"

if ! test "1" = $(${IFC} | grep -c UP); then
	POST_IFC="${IFC} down";
	PRE_IFC="${IFC} up";
fi

${PRE_IFC}

if ! test "0" = "$?"; then
	$POST_IFC;
	exit ${CODE1};
fi

if ! test "1" = $(${IFC} | grep -c RUNNING); then
	$POST_IFC;
	exit ${CODE2};
fi

${POST_IFC}
test "0" = "$?" || exit ${CODE3};


exit ${CODE0};

