#!/bin/bash
# $Id$

# This file is part of ifplugd.
#
# ifplugd is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# ifplugd is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with ifplugd; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

set -e

WHEREAMI=/usr/sbin/whereami

if [ -z "$1" ] || [ -z "$2" ] ; then
	echo "Usage: $0 <iface> (up|down)" 1>&2
	exit 1
fi

if [ -x $WHEREAMI ]; then
  $WHEREAMI --syslog --run_from ifplugd --hint $1,$2
else
  if [ "$2" = "up" ]; then
    [ -x /etc/init.d/wlan ] && /etc/init.d/wlan up $1
    /sbin/ifup $1
    exit $?
  elif [ "$2" = "down" ]; then
    /sbin/ifdown $1
    sleep 5
    [ -x /etc/init.d/wlan ] && /etc/init.d/wlan down $1
    exit $?
  fi
fi

exit 0
