#!/bin/sh

RT5370_DRIVER1=/lib/modules/sylinux/char/rtutil5370sta.ko
RT5370_DRIVER2=/lib/modules/sylinux/char/rt5370sta.ko
RT5370_DRIVER3=/lib/modules/sylinux/char/rtnet5370sta.ko

MT7601_EXIST=`/usr/bin/lsusb | grep :5370`
INSTALLED_WLAN_FILE=/var/log/installed_wlan
WLAN_IFNAME=/var/log/wlan_ifname

if [ -n "$MT7601_EXIST" ]; then
	echo "Loading rt5370 drivers ..."
	insmod $RT5370_DRIVER1
	insmod $RT5370_DRIVER2
	insmod $RT5370_DRIVER3
	# following code means a RaLink WiFi dongle not only RT3070
	echo "RT3070" > $INSTALLED_WLAN_FILE
	# ra0 up&down make to get WLAN MAC address
	/sbin/ifconfig ra0 up
	/sbin/ifconfig ra0 down
else
	# check gwdev is ra0 when no wlan-if
	. /etc/sysconfig/network
	if [ "$GATEWAYDEV" == "ra0" ]; then
		/bin/sed -i 's/ra0/eth0/g' /etc/sysconfig/network
	fi
fi

echo "ra0" > $WLAN_IFNAME

exit 0
