#!/bin/sh # # Nvidia Driver Installer for GoboLinux # Lucas Correia Villa Real # # Changelog: # 0.8 - fabio.m: Add --utility-prefix param, for install utilities in the # right place # 0.7 - New nvidia packages now support Linux-2.6: this script now recognizes # these releases; # Added '-c overwrite' flag to SymlinkProgram # 0.6 - Download and apply patches based on kernel version; did some cleanups. # 0.5 - Passing CC=`which gcc` to make # 0.4 - s/root/$correct_superuser/g on module's Makefile # 0.3 - Overriding compiler check # 0.2 - Reading release number from command line # 0.1 - First version # # # Functions used in the script # function ApplyPatches() { case "$1" in Linux-x86-1.0-5328*) DIFF="http://minion.de/files/NVIDIA_kernel-1.0-5328-2.6.diff" ;; Linux-x86-1.0-4620*) DIFF="http://minion.de/files/NVIDIA_kernel-1.0-4620-2.6.diff" ;; Linux-x86-1.0-4496*) DIFF="http://minion.de/files/NVIDIA_kernel-1.0-4496-2.6.diff" ;; Linux-x86-1.0-4363*) DIFF="http://minion.de/files/NVIDIA_kernel-1.0-4363-2.6.diff" ;; Linux-x86-1.0-4191*) DIFF="http://minion.de/files/NVIDIA_kernel-1.0-4191-2.6.diff" ;; Linux-x86-1.0-3123*) DIFF="http://minion.de/files/NVIDIA_kernel-1.0-3123-2.6.diff" ;; *) # Let the Force be with you FILE=`echo "$1" | cut -d"-" -f"4-5" | cut -d "." -f"1-2"` DIFF="http://minion.de/files/NVIDIA_kernel-$FILE-2.6.diff" ;; esac TOPDIR=`pwd` DIFF_FILE=`echo $DIFF | cut -d"/" -f5` echo "Downloading Linux-2.6 patches for NVIDIA release $1..." cd usr/src/ wget -nv "$DIFF" || { echo "Could not fetch remote file $DIFF" exit 1 } echo "Applying patches..." cd nv patch -p1 -i ../"$DIFF_FILE" || { echo "Could not successfully apply the patch" exit 1 } ln -s Makefile.kbuild Makefile cd "$TOPDIR" rm usr/src/"$DIFF_FILE" } function UpdateInstaller() { INST_FILE="nvidia-installer-1.0.5.tar.gz" INST_URL="ftp://download.nvidia.com/XFree86/nvidia-installer/$INST_FILE" DIFF_URL="http://minion.de/files/nvidia-installer-1.0.5-2.6.diff" DIFF_FILE=`echo $DIFF_URL | cut -d"/" -f5` echo "Downloading the NVIDIA installer..." wget -nv "$INST_URL" || { echo "Could not fetch remote file $INST_URL" exit 1 } echo "Downloading patches for the NVIDIA installer..." wget -nv "$DIFF_URL" || { echo "Could not fetch remote file $DIFF_URL" exit 1 } TOPDIR=`pwd` OFFSET=`python -c "print ${#INST_FILE} - 7"` DIRNAME="`echo "$INST_FILE" | cut -d"-" -f1- | cut -b-"$OFFSET"`" aunpack -q "$INST_FILE" || tar zxvf "$INST_FILE" || { echo "Could not uncompress file $INST_FILE" exit 1 } echo "Applying patches..." cd "$DIRNAME" patch -p1 -i "$TOPDIR/$DIFF_FILE" make || exit 1 strip nvidia-installer cp nvidia-installer "$TOPDIR"/ cd "$TOPDIR" rm "$INST_FILE" "$DIFF_FILE" } function VerifyRelease() { # # Checks if the release does support Linux 2.6 # _VERSION=`echo $RELEASE | cut -d"-" -f4` if [ "$_VERSION" -ge 5336 ]; then OLD_RELEASE=no else OLD_RELEASE=yes fi } function ModifyMakefile() { SRC="$1" DST=usr/src/nv/Makefile.gobo USER=`grep ":0:0:" /System/Settings/passwd | cut -d":" -f1` GROUP=`grep ":0:" /System/Settings/group | cut -d":" -f1` sed "s/-o\ root/-o\ $USER/g" $SRC > $DST && mv $DST $SRC sed "s/-g\ root/-g\ $GROUP/g" $SRC > $DST && mv $DST $SRC sed 's/usr\/share\/doc\/NVIDIA_GLX-\$(DSOMAJOR).\$(DSOMINOR)//g' < $SRC > $DST && mv $DST $SRC } # # Check the arguments # [ ! $# -eq 1 ] && { echo "Syntax: $0 " exit 1 } [ ! -f "$1" ] && { echo "$1 is not a regular file" exit 1 } # # The release number of the NVIDIA driver # OFFSET=`python -c "print ${#1} - 11"` RELEASE="`echo "$1" | cut -d"-" -f2- | cut -b-"$OFFSET"`" OLD_RELEASE=no DESTDIR="/Programs/Nvidia/$RELEASE/" XFREE_PATH="$DESTDIR" KERNELSRC="/System/Kernel/Modules/`uname -r`/build" MODULEDIR="/System/Kernel/Modules/`uname -r`/kernel/drivers/video" PROCDIR="/System/Kernel/Status" LOG_COMPILE="/System/Variable/log/nvidia-compile.log" # # Installer options. # #UPDATE="--update" UPDATE="" COMMON_FLAGS="--accept-license --opengl-headers -b -n --no-runlevel-check" #"-c --expert" X_PATH="--xfree86-prefix=$XFREE_PATH" GLPATH="--opengl-prefix=$DESTDIR" BINPATH="--installer-prefix=$DESTDIR" UTILPATH="--utility-prefix=$DESTDIR" MODULEPATH="--kernel-install-path=$MODULEDIR" PROCPATH="--proc-mount-point=$PROCDIR" # # Extract the installer # chmod +x NVIDIA-$RELEASE.run && ./NVIDIA-$RELEASE.run --extract-only cd NVIDIA-$RELEASE VerifyRelease # # Check for the kernel version and patch the source code, if needed # KERNVERS=`uname -r | cut -d"." -f"1-2"` if [ "$KERNVERS" = "2.6" -a "$OLD_RELEASE" = "yes" ]; then ApplyPatches "$RELEASE" UpdateInstaller "$RELEASE" SRC=.manifest DST=.manifest-2.6 sed "s/nvidia.o/nvidia.ko/g" $SRC > $DST && mv $DST $SRC KERNELPATH="--kernel-source-path=$KERNELSRC" else if [ "$KERNVERS" = "2.6" ]; then KERNELPATH="--kernel-source-path=$KERNELSRC" else KERNELPATH="--kernel-include-path=$KERNELSRC/include" fi fi # # Modify a few entries on the module's Makefile # if [ "$OLD_RELEASE" = "yes" ]; then ModifyMakefile "usr/src/nv/Makefile" else ModifyMakefile "usr/src/nv/Makefile.kbuild" ModifyMakefile "usr/src/nv/Makefile.nvidia" fi # # Override compiler check # export IGNORE_CC_MISMATCH="1" # # Prepare /Programs/Nvidia # #PrepareProgram -k -s Nvidia "$RELEASE" #ln -nfs /Programs/Nvidia/"$RELEASE" /Programs/Nvidia/Current DisableProgram Nvidia PrepareProgram -t Nvidia "$RELEASE" # # Run the installer # ./nvidia-installer $UPDATE \ $COMMON_FLAGS \ $X_PATH \ $GLPATH \ $BINPATH \ $UTILPATH \ $KERNELPATH \ $MODULEPATH \ $PROCPATH # # Run SymlinkProgram # SymlinkProgram -c overwrite Nvidia "$RELEASE"