#!/bin/bash
# Check if the X server is running
pid_of_X=`ps aux | grep X | grep -v 'grep' | grep root | awk '{ print $2 }'`
if [ -z "$pid_of_X" ];
then
echo -e '\n\n\n\n\n\n\n\n\n'
echo -e 'X is not running! - Good!\n'
# Stop the xserver (GDM)
sudo /etc/init.d/gdm stop
cd $HOME/Desktop
if [ -e latest.txt ]; # Check for 'latest.txt' file
then
rm -f latest.txt
fi
if [ -e NVIDIA-Linux-x86-* ]; # Check for 'NVIDIA-Linux-x86-*' file
then
rm -f NVIDIA-Linux-x86-*
fi
# Get the latest driver from NVIDIA's ftp
nvidia_ftp='ftp://download.nvidia.com/XFree86/Linux-x86'
wget -c -T 10 $nvidia_ftp/latest.txt
new_driver_version=`cat latest.txt | awk '{ print $1 }'`
new_driver_filename=`cat latest.txt | awk '{ print $2 }'`
wget -c -T 10 $nvidia_ftp/$new_driver_filename
chmod +x $HOME/Desktop/NVIDIA-Linux-x86-*
# Remove all nvidia* packages in the system
sudo dpkg -l | grep nvidia | awk '{ print $2 }' | xargs sudo aptitude -y purge
# Remove all the nvidia kernel objects currently installed
export kernel_version=`uname -r`
sudo rm -f `find /lib/modules/$kernel_version -iname nvidia.ko`
# Install the new driver
sudo sh $HOME/Desktop/NVIDIA-Linux-x86-*.run
rm -f NVIDIA-Linux-x86-*
rm -f latest.txt
echo -e '\n\n\n\n\n\n\n\n\n'
echo -e '---------\n'
echo -e 'All done!\n'
echo -e 'Starting GDM in 5 seconds...\n'
sleep 5
# Start GDM
sudo /etc/init.d/gdm start
else
echo -e '\n\n\n\n\n\n\n\n\n'
echo -e 'X is running!\n'
echo -e 'You should run this script in console mode!\n'
echo -e 'Press CTRL+ALT+F1 to go to console mode, then run this script again!\n'
echo -e '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'
echo -e 'Aborting in 5 seconds!'
echo -e '\n\n\n\n\n\n\n\n\n'
sleep 5
exit 0
fi