#!/bin/sh

# This script will install the ATI drivers on your PC
# This installation is for Edgy, for Feisty enable the restricted drivers
# Envy can also be used to install ATI drivers
# This script must be run as root with 755 permissions
#
# Authored by Bob Nelson  admin@stchman.com
#

script_name="ati_install.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

# backup the xorg.conf file
sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf_bkp

# The script will add the following to xorg.conf file at the very end
sudo echo -e '\n' >> /etc/X11/xorg.conf
sudo echo "# Added by the ati_install.sh script " >> /etc/X11/xorg.conf
sudo echo "Section "\"Extensions\"" >> /etc/X11/xorg.conf
sudo echo "Option  "\"Composite\"" "\"Disable\"" >> /etc/X11/xorg.conf
sudo echo "EndSection" >> /etc/X11/xorg.conf

sudo apt-get update
sudo apt-get install module-assistant build-essential
sudo apt-get install fakeroot dh-make debhelper debconf libstdc++5 linux-headers-$(uname -r)

# get the ATI drivers from www.stchman.com
# change to users home folder
cd ~

# this will download the drivers to the users home folder
wget http://www.stchman.com/tools/ati-driver-installer-8.32.5-x86.x86_64.run

# Convert the drivers to .deb files
sudo ln -sf bash /bin/sh
bash ati-driver-installer-8.32.5-x86.x86_64.run --buildpkg Ubuntu/edgy
sudo ln -sf dash /bin/sh

# Install the .deb files
sudo dpkg -i xorg-driver-fglrx_8.32.5-1*.deb
sudo dpkg -i fglrx-kernel-source_8.32.5-1*.deb
sudo dpkg -i fglrx-control_8.32.5-1*.deb

# Configuration
sudo module-assistant prepare
sudo module-assistant update
sudo module-assistant build fglrx
sudo module-assistant install fglrx
sudo depmod -a

sudo aticonfig --initial
sudo aticonfig --overlay-type=Xv

# remove the driver installer as it is no longer needed
rm -f ~/ati-driver-installer-8.32.5-x86.x86_64.run

# remove the .deb files as they are no longer needed
rm -f ~/xor*.deb
rm -f ~/fgl*.deb

# reboot the PC
sudo shutdown -r now 
