3 ###############################################################################
5 # Name : redo_nvidia_drivers #
6 # Author : Chris Koeritz #
7 # Rights : Copyright (C) 2004 #
11 # This shell script can re-build the NVIDIA graphics drivers for Linux #
12 # after a new kernel has been installed, given a few prerequisites: #
14 # 1) You are logged in as root. #
15 # 2) You are logged in at a console, and not under X. (Use the key #
16 # combo Ctrl-Alt-F1 to get to the first console.) #
17 # 3) The home directory for root has a subdirectory called "drivers". #
18 # 4) The drivers directory contains at least one NVIDIA graphics driver #
19 # that they offer in the form of NVIDIA-Linux-x86-1.0-6111-pkg1.run #
20 # or some similar hideous name. #
23 # After this script is successfully run, it will leave the system at the #
24 # X windows login screen. Note that the root user will still be logged #
25 # in back on the console where the script was executed. You should go #
26 # back to the console again and log out before considering the system to #
29 # Note for SuSE users: #
30 # After you run this script successfully, then you should not need to #
31 # run SaX to set up your display and video card. They should already #
32 # be correct from your previous settings. If, however, this is the #
33 # first time you've ever installed the driver, then you may have to #
34 # run SaX and fiddle with settings to get them right. The key in SaX #
35 # is to get the best match for your monitor, to ensure that your video #
36 # driver is the appropriate choice for your video card, and to ensure #
37 # that SaX says it will use the 'nvidia' driver (not the 'nv' driver). #
39 ###############################################################################
40 # This script is free software; you can redistribute it and/or modify it #
41 # under the terms of the GNU General Public License as published by the Free #
42 # Software Foundation; either version 2 of the License or (at your option) #
43 # any later version. See "http://www.fsf.org/copyleft/gpl.html" for a copy #
44 # of the License online. Please send any updates to "fred@gruntose.com". #
45 ###############################################################################
47 # This script requires an up to date kernel source tree in /usr/src/linux,
48 # at least for SuSE 9.1 to work. You, as root, could make a symbolic link
49 # for that if it's missing:
50 # ln -s /usr/src/linux-2.6.x.y.z /usr/src/linux
51 # where the x.y.z is your current 2.4 or 2.6 kernel.
53 # get the current run level so we'll be in the same state afterwards.
54 export RUNLEV=$(runlevel | sed -e 's/.* \(.*\)$/\1/' )
55 #echo "The current run-level is \"$RUNLEV\"."
57 export DRIVER_DIR=$HOME/drivers/nvidia
58 # this is assuming a directory under root's home directory called "drivers"
59 # where the NVIDIA drivers are located in a subdirectory called "nvidia".
60 # this directory must exist and it must have at least one NVIDIA-Linux.*.run
62 if [ ! -d "$DRIVER_DIR" ]; then
63 echo "The driver directory $DRIVER_DIR does not exist. Either set that variable"
64 echo "in this script or create the directory and ensure that the NVIDIA driver"
65 echo "in the form "NVIDIA-Linux*.run" is present in it."
69 export KERNEL_VER=$(kernelversion)
71 echo "The current kernel version is $KERNEL_VER."
73 if [ "$KERNEL_VER" = "2.6" ]; then
74 echo "Going to linux source code directory..."
77 echo "Cloning the source tree configuration..."
78 make cloneconfig >"$(mktemp "$TMP/zz_cloneconfig.XXXXXX")"
80 echo "Preparing the source tree..."
81 make prepare >"$(mktemp $TMP/zz_prepare_all.XXXXXX)"
84 echo "Going to root's drivers directory..."
87 if [ "$RUNLEV" != "3" ]; then
88 # X windows might still be running. let's go to single user mode.
89 echo "Ensuring that X-windows is shut down..."
91 sleep 7 # give it a little time to close things.
93 echo "X-windows is already shut down."
96 # this script supports the NVIDIA-Linux-x86.XXXX.run version of the nvidia
97 # driver. the ".run" file is just a shell script that we can easily
100 # replace SOME_NVIDIA_PACKAGE definition below if you don't want it to
101 # pick the first one it finds in the drivers directory. i tend to only have
102 # the most current one in there anyway, so this works and i don't need to
103 # keep updating the batch file.
104 export SOME_NVIDIA_PACKAGE=$(find . -name "NVIDIA-Linux*.run" | head -1)
105 if [ -z "$SOME_NVIDIA_PACKAGE" ]; then
106 echo "No NVIDIA packages in the form NVIDIA-Linux*.run were found."
107 echo "Please download the latest NVIDIA graphics driver from the NVIDIA"
108 echo "web page: http://www.nvidia.com"
112 echo "Using the NVIDIA package called: $SOME_NVIDIA_PACKAGE"
114 # we need to add an extra bit to the command if this is 2.6.
115 export SRC_PATH_EXTRA=
116 if [ "$KERNEL_VER" = "2.6" ]; then
117 export SRC_PATH_EXTRA='--kernel-source-path /usr/src/linux'
120 if ! bash $SOME_NVIDIA_PACKAGE $SRC_PATH_EXTRA ; then
121 echo "command was: bash $SOME_NVIDIA_PACKAGE $SRC_PATH_EXTRA"
123 echo "Did you cancel the installation? If not, then it failed."
127 if [ "$RUNLEV" != "3" ]; then
128 echo "If everything went successfully, then we should be able to start up"
129 echo "the X Window System right now. Let's see..."
132 echo "You'll have to start X-windows yourself to test the new driver; we're"
133 echo "staying in the previous single-user mode."