#!/bin/sh

#Check that script is running under root (this is really only to stop any normal user finding and trying to run this script manually....... yes someone out there will find it and try to run it!)
if [ "$UID" != "0" ]; then
        echo "This script must be run as root."
        exit 0
fi

#We should check to see if the atd daemon is installed
if [ ! -f /etc/rc.d/init.d/atd ] ; then
	echo "We require the atd demon to run this script"
	exit 0
fi

#We should check to see if atd is running and if not, start it
if ! service atd status | grep "pid" > /dev/null ; then
	echo "Starting the atd daemon"
	service atd start > /dev/null
fi

sleep 4  #This sleep is to ensure there is additional time to install other rpms... is it too long or short?

### restart X after nvidia driver installation is complete question
zenity --display=:0 --question --title="X Window System Restart Required" --text="MDE-Nvidia has detected that you have just uninstalled the Nvidia driver. In order to finalize the driver uninstallation, an X restart is required. 

If you wish to restart X now, please ensure all rpms have finished installing and your current work is saved, then close all applications and then select 'OK' to to proceed, otherwise select 'Cancel' to prevent X from restarting.

**PLEASE NOTE: If you chose not to restart X now, you will have to reboot your pc at a later stage to finish the nvidia driver installation**"

RESTART=$?

# If they do not want to restart X
if [ "$RESTART" = "1" ]; then
	exit 0

	# If they want to restart X
elif [ "$RESTART" = "0" ]; then
	sleep 1
	echo '/usr/sbin/nv-restart' | at now
fi

