#!/bin/bash
ASUS_WLED=/proc/acpi/asus/wled
DEV_WLAN=eth1
MODS_WLAN="ipw2100 ieee80211_crypt_wep ieee80211 ieee80211_crypt"
ISUP="unbelegt"

/sbin/ifconfig | /bin/grep $DEV_WLAN 2>&1 >/dev/null
#STAT="$?"
#logger "STAT=$STAT"
#if ["$STAT"=="1"]; then
if [ "$?" == "1" ]; then # is down
        ISUP="down"
        logger "isup=$ISUP"
	logger "MODS_WLAN=$MODS_WLAN"
        /sbin/modprobe $MODS_WLAN
        sleep 1
	/sbin/ifup $DEV_WLAN
	if [ "$?" == 0 -a -r $ASUS_WLED ]; then
		echo -n 1 > $ASUS_WLED
	fi
else # is up
	ISUP="up"
	logger "isup=$ISUP"
	/sbin/ifdown $DEV_WLAN
	sleep 1
	/sbin/rmmod --wait $MODS_WLAN
	if [ "$?" == 0 -a -r $ASUS_WLED ]; then
		echo -n 0 > $ASUS_WLED
	fi
fi

exit 0