#!/bin/bash
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH

echo -n "Blacklisting the bcm43xx module..."
echo "blacklist bcm43xx" | tee -a /etc/modprobe.d/blacklist
echo "Installing ndiswrapper..."
apt-get install ndiswrapper-utils-1.9
mkdir ~/bcm43xx
cd ~/bcm43xx
apt-get install cabextract
echo "Downloading and installong the driver..."
wget ftp://ftp.compaq.com/pub/softpaq/sp33001-33500/sp33008.exe
cabextract sp33008.exe
ndiswrapper -i bcmwl5.inf
ndiswrapper -l
depmod -a
echo "Enabling ndiswrapper..."
modprobe ndiswrapper
cp /etc/network/interfaces /etc/network/interfaces.orig
echo -e "auto lo\niface lo inet loopback\n" | tee /etc/network/interfaces
ndiswrapper -m
echo "ENABLED=0" | tee -a /etc/default/wpasupplicant
echo "Making the changes permanent after reboots..."
cp /etc/rc.local /etc/rc.local.origcat
echo -e "# ssb + ndiswrapper fix\nlogger \"rc.local ndiswrapper init\"\nMODULELIST=\`lsmod |awk '{print \$1}'\`\nMODULESRM=\"b43 b44 b43legacy ssb ndiswrapper\"\nMODULESADD=\"ndiswrapper ssb b44\"\nfor i in \$MODULESRM; do\n\tif [ \`echo \"\$MODULELIST\" |grep \"^\${i}$\"\` ]; then\n\t\techo \"Unloading module \$i\"\n\t\trmmod $i \n\tfi\ndone\n\nfor i in \$MODULESADD; do\n\t\techo \"Loading module \$i\"\n\t\tmodprobe $i \ndone\n# end\n\nexit 0\n" | tee /etc/rc.local
echo "Cleaning up temporary files..."
rm -rf bcm43xx/
echo "Done."
echo
echo "Please reboot typing: init 6"

exit 0
