#!/bin/sh

# This script will install the madwifi drivers for Atheros cards.
# The script must be run in a root terminal with 755 permission
#
# Authored by Bob Nelson  admin@stchman.com
#

script_name="madwifi.sh"

# Script must run as root 
if [ $USER != "root" ]; then
	echo "You need to run this script as root."
	echo "Use 'sudo ./$script_name' then enter your password when prompted."
	exit 1
fi

# Install essential tools
sudo apt-get -y install build-essential bin86

# Install the sharutils package
sudo apt-get -y install sharutils

# Change to the /usr/src folder
cd /usr/src

# Get the necessary drivers from www.stchman.com
sudo wget http://www.stchman.com/tools/madwifi/madwifi-0.9.3.3.tar.gz

# unpack the tarball
sudo tar -xzf /usr/src/madwifi-0.9.3.3.tar.gz

# Change to the folder that the tarball created
cd /usr/src/madwifi-0.9.3.3

# Make the drivers
sudo make clean
sudo make
sudo make install

# Make backup of /etc/modules file
sudo cp /etc/modules /etc/modules.bak

# Append to the end of the /etc/modules file by using >>
# First insert a carriage return in to the /etc/modules file
sudo echo -e '\n' >> /etc/modules
sudo echo "ath_pci" >> /etc/modules

# Enable WEP, WPA. WPA2 via network manager
# Install wpa supplicant
sudo apt-get -y install wpasupplicant

# Install Network Manager (this will allow you to see all available wireless networks)
sudo apt-get -y install network-manager-gnome network-manager

# Make backup of the /etc/network/interfaces file
sudo cp /etc/network/interfaces /etc/network/interfaces.bak

# Make new /etc/network/interfaces file with just "lo" entry in it.
# The single > will create a new file, >> appends to a file
sudo echo "# The loopback network interface" > /etc/network/interfaces
sudo echo "auto lo" >> /etc/network/interfaces
sudo echo "iface lo inet loopback" >> /etc/network/interfaces

# Create a file called /etc/default/wpasupplicant
# This file does not exist, but the > command will create it
sudo echo "ENABLED=0" > /etc/default/wpasupplicant

#sudo touch /etc/default/wpasupplicant

# Reboot the machine, wireless should now be enabled!!!!
sudo reboot

