#!/bin/sh

mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs none /dev
insmod /lib/modules/3.10.65/xradio_mac.ko
insmod /lib/modules/3.10.65/xradio_core.ko
#sleep 1
insmod /lib/modules/3.10.65/xradio_wlan.ko
#sleep 1

ifconfig wlan0 up
ifconfig wlan0 192.168.100.1
route add default gw 192.168.100.1 wlan0

/etc/sd-spi-sw/sdspiinit.sh 

hostapd /etc/hostapd.conf -B

udhcpd /etc/udhcpd.conf
sleep 1

ftpd -f /etc/ftpd.conf

#echo /sbin/sd-plug > /sys/kernel/uevent_helper

VFAT_DIR=/mnt
TEST_APP_RUN_FILE=/mnt/run.sh
APP_RUN_FILE=/app/run.sh
TF_CARD_PATH=/dev/mmcblk0

if [ -e "${TF_CARD_PATH}" ]; then
        echo "find testing firmware ..."
        mount -t vfat ${TF_CARD_PATH} ${VFAT_DIR}
        if [ $? -eq 0 ]; then
                if [ -e "${TEST_APP_RUN_FILE}" ]; then
                        cd /mnt
                        ${TEST_APP_RUN_FILE} &
                        cd /
                else
                        umount ${VFAT_DIR}
                        cd /app
                        ${APP_RUN_FILE} &
                        cd /
                fi
        else
                umount ${VFAT_DIR}
                cd /app
                ${APP_RUN_FILE} &
                cd /
        fi
else
        cd /app
        ${APP_RUN_FILE} &
        cd /
fi

/sbin/getty -L ttyS1 115200 vt100 -n -l /bin/ash


