#!/bin/bash

base_dir="/opt/hp/graphics/nvidia"

echo "Unconfiguring NVIDIA OEM driver..."

# Uninstall driver, silently:
/usr/bin/nvidia-installer --silent --uninstall

# Make 'nvconfig' inactive:
/sbin/chkconfig --del nvconfig > /dev/null

# Remove nvidia-settings soft link:
if [ -L "${base_dir}/nvidia-settings" ]; then
	rm -f ${base_dir}/nvidia-settings
fi

# Remove nvidia-xconfig soft link:
if [ -L "${base_dir}/nvidia-xconfig" ]; then
	rm -f ${base_dir}/nvidia-xconfig
fi

# Remove/Restore X Config files:  

if rpm -q XFree86 >/dev/null;
then
   if [ -L "/etc/X11/XF86Config-4" ]; then
        rm -f /etc/X11/XF86Config-4
   fi
 
   if [ -L "/etc/X11/XF86Config" ]; then
        rm -f /etc/X11/XF86Config
   fi
 
   if [ -f "/etc/X11/XF86Config-4.save" ]; then
        mv -f /etc/X11/XF86Config-4.save /etc/X11/XF86Config-4
   fi
 
   if [ -f "/etc/X11/XF86Config.save" ]; then
        mv -f /etc/X11/XF86Config.save /etc/X11/XF86Config
   fi
                                                                                                                  
   if [ -f "/etc/X11/XF86Config-4.nvidiaStandard" ]; then
        rm -f /etc/X11/XF86Config-4.nvidiaStandard
   fi
else
   if [ -L "/etc/X11/xorg.conf" ]; then
        rm -f /etc/X11/xorg.conf
   fi
 
   if [ -f "/etc/X11/xorg.conf.save" ]; then
        mv -f /etc/X11/xorg.conf.save /etc/X11/xorg.conf
   fi
 
   if [ -f "/etc/X11/xorg.nvidiaStandard" ]; then
        rm -f /etc/X11/xorg.nvidiaStandard
   fi
fi
echo "COMPLETE." 

exit 0
