#!/bin/sh
#
# install_intersil_firmware
#
# This script tries to download and install the firmware needed to run
# WLAN cards using the ACX100 chip.
URL="ftp://ftp2.dlink.com/PRODUCTS/DWL-520PLUS/REVA/"
FWFILE="DWL-520PLUS_DRIVER_3.07_WIN.ZIP"

die()
{
    cd - >/dev/null
    test -d $TMPDIR
    rm -rf $TMPDIR
    exit 1
}

curldie()
{
    cd - >/dev/null
    test -d $TMPDIR
    rm -rf $TMPDIR
    echo ""
    echo ""
    echo "Could not find firmware ${FWFILE} at:"
    echo ""
    echo "${URL}"
    echo ""
    echo "You might want to search for it at a different location in the internet"
    echo "Press <ENTER> to proceed - I quit now"
    read ANT
    exit 1
}

test "${UID}" = "0" || { echo "You have to be root to do this!"; exit 1; }
test -z "$( type -p curl)" && { echo "'curl' is not installed, aborting"; exit 1; }
test -z "$( type -p unzip)" && { echo "'unzip' is not installed, aborting"; exit 1; }
test -d /lib/firmware || mkdir -p /lib/firmware

TMPDIR=$(mktemp -d /var/tmp/acx100.XXXXXX) || exit 1

cd $TMPDIR
echo "Downloading firmware"
curl -# -o ${FWFILE} ${URL}/${FWFILE}
echo -n "Installing firmware"
unzip $FWFILE >/dev/null || die
install -m0644 Drivers/Win2000/WLANGEN.bin /lib/firmware/WLANGEN.BIN || die
install -m0644 Drivers/Win2000/RADIO0d.BIN /lib/firmware/RADIO0d.BIN || die
install -m0644 Drivers/Win2000/RADIO11.BIN /lib/firmware/RADIO11.BIN || die
echo
echo "Firmware successfully installed."

cd - >/dev/null
rm -rf $TMPDIR

exit 0
