#!/bin/sh
#
# install_intersil_firmware
#
# This script tries to download and install the firmware needed to run
# WLAN cards using Intersil's PrismGT chip.
URL=ftp://ftp.funkwerk-ec.com/bintec/old_products/artem/client_cards/11g
FWFILE=CC-54g_v1017.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/intersil.XXXXXX) || exit 1

cd $TMPDIR
echo "Downloading firmware"
curl -# -o $FWFILE $URL/$FWFILE || curldie
echo -n "Installing firmware"
unzip $FWFILE >/dev/null || die
install -m0644 ComCard\ 54g/Win2k/WLANDCB.arm /lib/firmware/isl3890 || die
echo
echo "Firmware successfully installed."

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

exit 0
