#!/bin/sh
#
#
PATH=/sbin:/usr/sbin:/usr/bin:$PATH
PKG=RDIwavelan
ETC=/etc
USR=/usr
DRVDIR=${BASEDIR}/kernel/drv
DRIVER=wavelan
BASE=`pwd`
OSVERSION=`uname -r`
#
echo "Installing PCMCIA WaveLAN WireLess Ethernet Driver for SunOS ${OSVERSION}"
#
# Add the driver to the system
#
modinfo | grep ${DRIVER} > /dev/null 2>&1
if [ $? = 0 ]; then
#
#	remove old driver
#
	echo "removing old $PKG..."
	ifconfig wl0 unplumb > /dev/null 2>&1 
	ifconfig wl1 unplumb > /dev/null 2>&1 
	echo "remove the PCMCIA WaveLan card then enter any key to continue"
	read x
	mid=`modinfo | grep ${DRIVER} | awk '{ print $1 }'`
	modunload -i $mid
	rem_drv ${DRIVER}
fi

cd ${DRVDIR}
if [ -f ${DRIVER} ]
then
#
#		use -i option to create driver aliases in /etc/driver_aliases
#
	add_drv -m "* 0666 root sys" -i "PC,NCR WaveLAN" ${DRIVER} > /dev/null 2>&1
#	add_drv -m "* 0666 root sys" -i "PC,NCR WaveLAN" ${DRIVER}
	if [ $? != 0 ]
	then
		echo "NOTICE: WaveLan card not inserted..."
	fi
else
	echo "add_drv failed: ${DRIVER} not found..."
	exit 1
fi
#
#
echo "editing /etc/driver_aliases..."
ed /etc/driver_aliases << EOM > /dev/null
\$p
a
wavelan "PC,NCR WaveLAN/PCMCIA Version 1.00 "
wavelan "PC,AT&T WaveLAN/PCMCIA Version 2.00 "
.
w
q
EOM
#
#
grep wavelan /etc/name_to_major > /dev/null
if [ $? = 1 ]; then
	echo "adding entry for WaveLan in /etc/name_to_major..."
	awk '{ print $2 }' /etc/name_to_major  > /tmp/$$
	last=`sort -n /tmp/$$ | tail -1`
	new=`expr $last + 1`
	echo "wavelan $new" >> /etc/name_to_major
	echo "assign major number $new to WaveLan driver"
	rm -f /tmp/$$
fi

#--
echo "type=ddi_pseudo;name=${DRIVER}	wl" >> /etc/devlink.tab
#
#	create link from /dev/wl to real device /devices/pseudo/clone@0:wl
devlinks
#
#	create /etc/wlhostname.wl0
#
h=`uname -n`
hn=$h"_air"
echo $hn > /etc/wlhostname.wl0
echo "Created /etc/wlhostname.wl0 for WaveLAN 0"
#
#       add an IP address for the interface in hosts file
#
host=`grep  "[ ,        ]$hn" /etc/hosts | awk '{ print $2 }'`
if [ "$host" = "$hn" ]; then
        grep -v "[ ,    ]$hn" /etc/hosts > /tmp/$$
        echo "$IPADDR   $hn" >> /tmp/$$
        mv /tmp/$$ /etc/hosts
else
        echo "$IPADDR   $hn" >> /etc/hosts
fi
#
#
echo "${PKGINST} has been installed."
echo ""
echo "****"
echo "*********************************************************************"
echo "**** WaveLAN interface wl0 configuration: $IPADDR	$hn"
echo "*********************************************************************"
echo "****"
echo ""
echo "**** The system needs to be rebooted (boot -r) for the changes to take effect"
echo "****"
exit 0
