#!/bin/sh

wget ftp://ftp.embeddedarm.com/ts-arm-sbc/ts-7500-linux/binaries/wifi/lib/zd1211/zd1211rw_ts7500.ko

DIR="/lib/modules/2.6.24.4/kernel/drivers/net/wireless/"

echo -n "Copying drivers to $DIR/zd1211rw/... "
mkdir $DIR/zd1211rw/ > /dev/null 2> /dev/null
mv zd1211rw_ts7500.ko $DIR/zd1211rw/zd1211rw.ko
echo "done"

# Add zd1211rw to /etc/modules for loading on startup
# First, remove zd1211rw from list first just in case user ran script before
echo -n "Adding zd1211rw module to /etc/modules for auto load on startup... "
sed -i 's/zd1211rw//g' /etc/modules
echo "zd1211rw" >> /etc/modules
sed -i '/^$/d' /etc/modules
echo "done"

# Install necessary zd1211rw firmware files
echo -n "Running zd1211 firmware installation script... "
if [ -e /lib/firmware/zd1211/zd1211_ub ]; then
   echo "firmware already installed, nothing done"
else
   wget ftp://ftp.embeddedarm.com/ts-arm-sbc/ts-7500-linux/binaries/wifi/bin/firmware_zd1211/zd1211-firmware-1.4.tar.gz
   tar xzf zd1211-firmware-1.4.tar.gz -C / > /dev/null 2> /dev/null
   echo "done"
fi

rm -f zd1211-firmware-1.4.tar.gz

# Build module dependancies and install module
echo -n "Inserting zd1211rw.ko module using modprobe... "
depmod -a
modprobe zd1211rw
if [ $? -eq 0 ]; then
   echo "done"
   echo
   echo "The zd1211rw wireless driver permanently installed."
   echo "Please refer to Linux documentation for setting up"
   echo "your network using /etc/interfaces/network config file."
   echo
else
   echo 
   echo "Modprobe failed.  You may need to install manually."
   echo
fi
