-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

#!/bin/sh

EULA="http://www.nvidia.com/object/nv_swlicense.html"

ARCH="x86"
VERSION=1.0-7676
PKG="pkg1"

if [ "`uname -m`" == "x86_64" ]; then
  ARCH="x86_64"
  VERSION=1.0-7676
  PKG="pkg2"
fi

FILE="NVIDIA-Linux-${ARCH}-${VERSION}-${PKG}.run"
DRIVER="http://download.nvidia.com/XFree86/Linux-${ARCH}/${VERSION}/${FILE}"
CURL_OPTIONS="-s"

if [ "`id -u`" != "0" ]; then
  echo "error: You must be root to use this program."
  exit 1
fi

/sbin/lspci -n|grep -q "0300:.*10de:"
if [ $? -ne 0 ]; then
  echo "No nvidia graphics board found."
  exit 0
else
  device_id=$(/sbin/lspci -n|grep "0300:.*10de:"| \
              cut -d ":" -f 4|awk '{print $1}')
  case $device_id in
    0020 | \
    0028 | \
    0029 | \
    002C | \
    002D | \
    00A0 | \
    0100 | \
    0101 | \
    0103 | \
    0150 | \
    0151 | \
    0152 | \
    0153)
      echo -n "Legacy nVidia chipsets are no longer supported since "
      echo    "driver version 1.0-7664"
      exit 0
      ;;
    *)
      ;;
  esac
fi

# --dir "absolute_path_to_downloaded_driver"
if [ "$1" = "--dir" ]; then
  DIR="$2"
  if [ -z "$DIR" ]; then
    echo "--dir requires an argument."
    exit 1
  fi
fi

if [ -z $http_proxy ]; then
  echo 
  echo "note: No proxy is used. Please set the environment variable \"http_proxy\""
  echo "note: to your favorite proxy, if you want to use a proxy for the download."
  echo "note:"
  echo "note:   bash: export http_proxy=\"http://proxy.provider.de:3128/\""
  echo "note:   tcsh: setenv http_proxy \"http://proxy.provider.de:3128/\""
  echo
fi

/usr/X11R6/bin/xsload -vendor | grep -q "nvidia:NVIDIA Corporation"
if [ $? -eq 0 ]; then
  echo "NVIDIA driver already installed!"
  exit 0
fi

# don't copy EULA if the driver is already downloaded
if [ -z "$DIR" -a ! -r /usr/share/doc/nvidia/EULA.html ]; then
  echo "EULA:"
  mkdir -p /usr/share/doc/nvidia
  echo    "  info: \"/usr/share/doc/nvidia/EULA.html\" not found."
  echo -n "  Fetching   ... "
  curl $CURL_OPTIONS -o /usr/share/doc/nvidia/EULA.html $EULA
  echo "done"
fi

tmpname=`basename $0`
tmpdir=`mktemp -d /tmp/$tmpname.XXXXXX`
if [ $? -ne 0 ]; then
  echo "$0: Can't create temp dir, exiting..."
  exit 1
fi

pushd $tmpdir &> /dev/null

for i in onetime; do
  file=`echo $DRIVER|awk -F "/" '{print $NF}'`
  echo "$file:"
  if [ -r /usr/share/doc/nvidia/$file ]; then
    echo -n "  Checking ... "
    test -s /usr/share/doc/nvidia/$file || rm -f /usr/share/doc/nvidia/$file
    sh /usr/share/doc/nvidia/$file --check &> /dev/null
    if [ $? -ne 0 ]; then
      echo "failed ... need to refetch"
      rm -f /usr/share/doc/nvidia/$file
    fi
  fi
  if [ ! -r /usr/share/doc/nvidia/$file ]; then
    echo -n "  Fetching ... "
    if [ -n "$DIR" ]; then
      cp "$DIR/$FILE" /usr/share/doc/nvidia/$file
      if [ $? -ne 0 ]; then
        echo "File not found: $DIR/$FILE."
        exit 1
      fi
    else
      curl $CURL_OPTIONS -o /usr/share/doc/nvidia/$file $DRIVER
    fi
    if [ $? -ne 0 ]; then
      echo "failed ... aborted!"
      continue
    fi
    chmod 755 /usr/share/doc/nvidia/$file
    echo done
  fi
  echo -n "  Installing ... "
  sh /usr/share/doc/nvidia/$file --extract-only &> /dev/null
  cd NVIDIA-Linux-*
  # let the installer think that the kernel module is loaded 
  # successfully; prevents some machines from crashing
  ln -snf /bin/true insmod
  ln -snf /bin/true rmmod
  # let the installer think that X11 is not running as it will fail 
  # otherwise
  if [ -f /tmp/.X0-lock ]; then
    tmpfile=`mktemp /tmp/.X0-lock.XXXXXXXXXX`
    mv /tmp/.X0-lock $tmpfile
  fi
  # Workaround for NVIDIA installer bug (#72299)
  modprobe agpgart
  PATH=`pwd`:$PATH ./nvidia-installer -s
  if [ $? -ne 0 ]; then
    echo "failed"
    continue
  fi
  # rescan 3D configuration for SaX2
  /usr/sbin/sysp -s 3d > /dev/null
  # install binary-only part of kernel module for kernel updates later
  cp usr/src/nv/nv-kernel.o /lib/modules/scripts/nvidia/nv-kernel.o-$VERSION
  echo "done"
  echo
  /usr/bin/switch2nvidia
  echo
done

# try to restore X11 socket savely
mktemp /tmp/.X0-lock &> /dev/null
if [ $? -eq 0 -a "$tmpfile" != "" ]; then
  cp $tmpfile /tmp/.X0-lock
  chmod 444 /tmp/.X0-lock
fi
test -f "$tmpfile" && rm $tmpfile
popd &> /dev/null
rm -rf $tmpdir
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQFDJqhqqE7a6JyACsoRAhQVAJ40spX00lHXBeKtEhmmuX1qsxkctACf
TxnsW4DLG8mPKeFpaXTRl8dyjqU=
=Lsi7
-----END PGP SIGNATURE-----
