config() {
  NEW="$1"
  OLD="$(dirname $NEW)/$(basename $NEW .new)"
  # If there's no config file by that name, mv it over:
  if [ ! -r $OLD ]; then
    mv $NEW $OLD
  elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
  # toss the redundant copy
    rm $NEW
  fi
  # Otherwise, we leave the .new copy for the admin to consider...
}
config etc/X11/xorg.conf.d/nvidia.conf.new
config etc/X11/xorg.conf.d/monitor.conf.new
config etc/modprobe.d/nvidia.conf.new

if [ -f usr/lib64/xorg/modules/extensions/libglx.so ];then
  mv usr/lib64/xorg/modules/extensions/libglx.so usr/lib64/xorg/modules/extensions/libglx.so-prenvidia
fi

if lsmod|grep -q nouveau;then
  echo "You MUST reboot your system!"
  echo
fi

if [ ! -f lib/modules/`uname -r`/kernel/drivers/video/nvidia.ko ];then
  echo "You MUST rebuild the kernel module by launch the script:"
  echo "/usr/share/nvidia-linux/makekernelmodule.sh"
fi
chroot . /sbin/depmod -a

( cd usr/lib64/xorg/modules ; rm -rf libnvidia-wfb.so.1 )
( cd usr/lib64/xorg/modules ; ln -sf libnvidia-wfb.so.310.19 libnvidia-wfb.so.1 )
( cd usr/lib64/xorg/modules/extensions ; rm -rf libglx.so )
( cd usr/lib64/xorg/modules/extensions ; ln -sf libglx.so.310.19 libglx.so )
( cd usr/lib64 ; rm -rf libnvidia-ml.so )
( cd usr/lib64 ; ln -sf libnvidia-ml.so.1 libnvidia-ml.so )
( cd usr/lib64 ; rm -rf libnvidia-ml.so.1 )
( cd usr/lib64 ; ln -sf libnvidia-ml.so.310.19 libnvidia-ml.so.1 )
( cd usr/lib64 ; rm -rf libnvidia-cfg.so )
( cd usr/lib64 ; ln -sf libnvidia-cfg.so.1 libnvidia-cfg.so )
( cd usr/lib64 ; rm -rf libnvidia-cfg.so.1 )
( cd usr/lib64 ; ln -sf libnvidia-cfg.so.310.19 libnvidia-cfg.so.1 )
( cd usr/lib64 ; rm -rf libnvcuvid.so )
( cd usr/lib64 ; ln -sf libnvcuvid.so.1 libnvcuvid.so )
( cd usr/lib64 ; rm -rf libnvcuvid.so.1 )
( cd usr/lib64 ; ln -sf libnvcuvid.so.310.19 libnvcuvid.so.1 )
( cd usr/lib64 ; rm -rf libcuda.so )
( cd usr/lib64 ; ln -sf libcuda.so.1 libcuda.so )
( cd usr/lib64 ; rm -rf libcuda.so.1 )
( cd usr/lib64 ; ln -sf libcuda.so.310.19 libcuda.so.1 )
( cd usr/lib64 ; rm -rf libOpenCL.so )
( cd usr/lib64 ; ln -sf libOpenCL.so.1 libOpenCL.so )
( cd usr/lib64 ; rm -rf libOpenCL.so.1 )
( cd usr/lib64 ; ln -sf libOpenCL.so.1.0 libOpenCL.so.1 )
( cd usr/lib64 ; rm -rf libOpenCL.so.1.0 )
( cd usr/lib64 ; ln -sf libOpenCL.so.1.0.0 libOpenCL.so.1.0 )
( cd usr/lib64 ; rm -rf libGL.so )
( cd usr/lib64 ; ln -sf libGL.so.1 libGL.so )
( cd usr/lib64 ; rm -rf libGL.so.1 )
( cd usr/lib64 ; ln -sf libGL.so.310.19 libGL.so.1 )
