#! /bin/bash # # build-nvidia-kernel # The use of this script is described on # http://www.xs4all.nl/~carlo17/howto/nvidia.html version="20100407.0" # Detect versions, get resources, assemble and fix debian/* # files and build nvidia kernel module package. # # Copyright (C) 2006 - 2010 Carlo Wood # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # USA. #----------------------------------------------------------------------------------------------- # Command line options. progname=$0 beta="no" kerneloption="no" force="no" kvers= option=$1 while test -n "$option"; do case $option in --runfile=* | --beta=*) beta="yes" gvers=`echo $option | sed -re 's/--(beta|runfile)=//' -e 's/1\.0\.([0-9]+)$/1.0-\1/'` ;; --runfile | --beta) beta="yes" shift gvers=$(echo "$1" | sed -re 's/1\.0\.([0-9]+)$/1.0-\1/') ;; --kernel=*) kvers=`echo $option | sed -e 's/--kernel=//'` kerneloption="yes" ;; --kernel) shift kvers=$1 kerneloption="yes" ;; --force) force="yes" ;; *) echo "* build-nvidia-kernel version $version -- Copyright (C) 2006-2008, Carlo Wood *" echo "Usage: $progname [--force] [--kernel=] [--runfile=]" echo "For example: $progname --kernel=$(uname -r) --runfile=169.09" echo "Run $progname without arguments to build a debian package backported" echo "from unstable for the running kernel. In order to use --runfile you need to have" echo "the matching NVIDIA-Linux-$rfarch-*-pkg*.run file downloaded and present in the" echo "current directory. The option --force, if present, will automatically delete" echo "previously generated directories if they are in the way." exit ;; esac shift option=$1 done #----------------------------------------------------------------------------------------------- # Collect data ARCH=`uname -m` case $ARCH in i*86) ARCH=`echo $ARCH | sed -e 's/i//'`; rfarch="x86"; ngmarch="i386"; ;; x86_64) ARCH="amd64"; rfarch="x86_64"; ngmarch="amd64" ;; *) echo "Sorry, arch $ARCH is not supported."; exit 1 ;; esac if test -n "$gvers"; then RUNFILE="`/bin/ls NVIDIA-Linux-$rfarch-$gvers-pkg*.run`" test -n "$RUNFILE" || exit 1 fi if test -n "$kvers"; then KVERS="$kvers" else # Get the latest kernel version. KVERS=`/bin/ls -t /lib/modules | head -n 1` if test "$KVERS" != "`uname -r`"; then echo "Running kernel version: $(uname -r)" echo "Last installed kernel version: $KVERS" echo "Please use --kernel= to make up your mind." exit 1 fi fi if ! test -d /lib/modules/$KVERS; then echo "/lib/modules/$KVERS: No such directory." exit 1 fi KVERSMM=`echo $KVERS | sed -re 's/^(2\.[0-9]+\.[0-9]+.*)-[^-]*/\1/'` if test "$KVERSMM" = "$KVERS"; then echo "Sorry, the kernel version ($KVERS) must be of the form VERSION-ARCH (ie, 2.6.32-3-amd64) or the nvidia build scripts will get confused." exit 1 fi case "$KVERS" in 2.6.*-[3-9]86) ;; 2.6.*-amd64) ;; 2.6.*) echo "Sorry, the kernel version, $KVERS, must be of the form 2.6.*-$ARCH.\nFor custom kernels use for example: make-kpkg --append-to-version=-\$(hostname)-$ARCH [...]."; exit 1 ;; *) echo "Sorry, the kernel version, $KVERS, must be of the form 2.6.*-$ARCH."; exit 1 ;; esac if test "$KVERS" != "$KVERSMM-$ARCH"; then echo "The architecture of the running kernel ($ARCH) is not the same as what you request to be compiled ($KVERS), and I can't do cross compiling." exit 1 fi echo "Building for kernel version = \"$KVERS\"" echo ">>> test -d $KVERS || mkdir $KVERS" test -d $KVERS || mkdir $KVERS || exit 127 echo ">>> cd $KVERS" cd $KVERS #----------------------------------------------------------------------------------------------- # install nvidia-kernel-common echo ">>> dpkg --list nvidia-kernel-common (quiet)" if ! dpkg --list nvidia-kernel-common | tail -n 1 | grep '^ii ' >/dev/null; then echo ">>> apt-get install nvidia-kernel-common" sudo apt-get install nvidia-kernel-common || exit 1 fi #----------------------------------------------------------------------------------------------- # Determine driver version to install TARGET= if test "$beta" = "no"; then echo ">>> sudo apt-get install --dry-run nvidia-glx (quiet)" GVERS=`sudo apt-get install --dry-run nvidia-glx | \ grep '^Inst nvidia-kernel-[^ ]* ([0-9][0-9]*\.[0-9][0-9.+]* Debian:unstable)$' | \ sed -e 's/^Inst nvidia-kernel-[^ ]* (\([0-9][0-9]*\.[0-9][0-9.+]*\) Debian:unstable)$/\1/'` #echo "4.GVERS=\"$GVERS\"" if ! (echo "$GVERS" | grep '^[0-9][0-9]*\.[0-9][0-9.]*' >/dev/null); then # This should mean that a nvidia-kernel-$KVERS is already installed. # Check if that is true. echo ">>> dpkg --list nvidia-kernel-$KVERS (quiet)" if ! dpkg --list nvidia-kernel-$KVERS | tail -n 1 | grep '^.i.' >/dev/null; then RESULT=$(sudo apt-get install --dry-run nvidia-glx 2>&1) if (echo "$RESULT" | grep 'nvidia-glx is already the newest version\.'); then INSTALLED=$(apt-cache policy nvidia-glx | awk '/Installed: / { gsub(/ *Installed: */, ""); print }') TARGET=$(apt-cache policy nvidia-glx | awk 'BEGIN { found=0 } \ /^ [ *]*[0-9][0-9]*\.[0-9][0-9.]*-[1-9]/ \ { gsub(/^ [ *]*/, ""); gsub(/ *[0-9]*$/, ""); \ if (found == 0) { found=1; target=$0 } } \ END { if (found) printf("%s\n", target); }') if test "$TARGET" = "$INSTALLED"; then exit 1 fi echo "INSTALLED=\"$INSTALLED\"; TARGET=\"$TARGET\"" GVERS=$(apt-cache policy nvidia-kernel-2.6-$ARCH | \ awk 'BEGIN { found=0 } \ /^ [ *]*[0-9][0-9]*\.[0-9][0-9.]*\+[1-9]/ \ { gsub(/^ [ *]*/, ""); gsub(/ *[0-9]*$/, ""); \ if (found == 0) { found=1; target=$0 } } \ END { if (found) printf("%s\n", target); }') #echo "3.GVERS=\"$GVERS\"" else echo "Failed to determine nvidia-graphics-module version (GVERS=\"$GVERS\")." exit 1 fi else # Check if maybe the user wants to build a beta version. LATESTRUN=$(cd ..; ls -t NVIDIA-Linux-$rfarch-*-pkg*.run | head -n 1) if test -z "$LATESTRUN"; then echo "nvidia-kernel-$KVERS is already installed." exit 0 fi GVERS=`echo "$LATESTRUN" | sed -e "s/NVIDIA-Linux-$rfarch-\([0-9][0-9]*\.[0-9][0-9.-]*\)-pkg.*\.run/\1/"` #echo "2.GVERS=\"$GVERS\"" if test "$GVERS" = "$LATESTRUN"; then echo "Failed to determine package version number from $LATESTRUN." else echo "Use $progname --runfile= to create a package with driver version ." if test "$kerneloption" = "yes"; then echo "For example: $progname --kernel=$kvers --runfile=$GVERS" else echo "For example: $progname --runfile=$GVERS" fi fi exit 1 fi fi echo "Compiling nvidia-graphics-modules-$ngmarch""_$GVERS" else GVERS=`echo "$gvers+beta" | sed -e 's/-/./'` #echo "1.GVERS=\"$GVERS\"" fi #----------------------------------------------------------------------------------------------- # Build nvidia-graphics-modules function nvidia_graphics_modules_change_log() { echo "nvidia-graphics-modules-$ngmarch ("$GVERS") unstable; urgency=low" echo echo " * build $KVERSMM modules for etch" echo " * use nvidia-kernel-source $gvers" echo echo -n " -- build-nvidia-kernel script by Carlo Wood " date +"%a, %_d %b %Y %T %z" } function nvidia_kernel_change_log() { echo "nvidia-kernel ("$USVERS"-0) unstable; urgency=low" echo echo " * New upstream." echo echo -n " -- build-nvidia-kernel script by Carlo Wood " date +"%a, %_d %b %Y %T %z" } function nvidia_graphics_drivers_change_log() { echo "nvidia-graphics-drivers ("$USVERS"-0) unstable; urgency=low" echo echo " * New upstream." echo echo -n " -- build-nvidia-kernel script by Carlo Wood " date +"%a, %_d %b %Y %T %z" } GRAPHICS_MODULES_TAR_GZ=`/bin/ls ../nvidia-graphics-modules-$ngmarch""_$GVERS.tar.gz 2>/dev/null` if test -z "$GRAPHICS_MODULES_TAR_GZ"; then # Attempt to download nvidia-graphics-modules-$ngmarch echo ">>> apt-get source -t unstable nvidia-graphics-modules-$ngmarch" (cd ..; apt-get source -t unstable nvidia-graphics-modules-$ngmarch) if test $? != 0; then echo "Do you have a deb-src for unstable non-free in your sources.list file? And if you just added it, did you re-run apt-get update?" exit 1 fi GRAPHICS_MODULES_TAR_GZ=`/bin/ls ../nvidia-graphics-modules-$ngmarch""_$GVERS.tar.gz 2>/dev/null` echo "GRAPHICS_MODULES_TAR_GZ=\"$GRAPHICS_MODULES_TAR_GZ\"" if test -z "$GRAPHICS_MODULES_TAR_GZ"; then if test "$beta" = "yes"; then # Find the latest version in the current directory. LATEST=`/bin/ls ../nvidia-graphics-modules-$ngmarch""_*.tar.gz | \ sed -re "s/.*nvidia-graphics-modules-$ngmarch"'_([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\+([^.]*)\.tar\.gz/\1 000000\2 000000\3 \4 \1.\2.\3+\4/' \ -e "s/.*nvidia-graphics-modules-$ngmarch"'_([[:digit:]]+)\.([[:digit:]]+)\+([^.]*)\.tar\.gz/\1 000000\2 \3 \1.\2+\3/' \ -e 's/ 0*([[:digit:]]{6,})/\1/g' | \ sort -n | tail -n 1 | sed -e 's/.* //'` # Create the target directory if test -d nvidia-graphics-modules-$ngmarch-$GVERS; then if test "$force" = "yes"; then rm -rf nvidia-graphics-modules-$ngmarch-$GVERS else echo "Confused... $(pwd)/nvidia-graphics-modules-$ngmarch-$GVERS already exists? Um, remove it?" echo "Use the option --force to REMOVE (previously) generated directories automatically." echo "The reason this isn't done by default is because you might be hacking those directories in order to get things working." echo "If you don't know what this means, then it should be safe to use --force." exit 1 fi fi echo ">>> mkdir nvidia-graphics-modules-$ngmarch-$GVERS" mkdir nvidia-graphics-modules-$ngmarch-$GVERS || exit 127 # Extract the old version echo ">>> tar -C nvidia-graphics-modules-$ngmarch-$GVERS -xzf ../nvidia-graphics-modules-$ngmarch""_$LATEST.tar.gz" tar -C nvidia-graphics-modules-$ngmarch-$GVERS \ -xzf ../nvidia-graphics-modules-$ngmarch""_$LATEST.tar.gz || exit 127 # While we're at it, remove junk from this tar ball. echo ">>> rm -rf nvidia-graphics-modules-$ngmarch-$GVERS/nvidia-graphics-modules-$ngmarch-$LATEST/debian/nvidia-kernel-*" rm -rf nvidia-graphics-modules-$ngmarch-$GVERS/nvidia-graphics-modules-$ngmarch-$LATEST/debian/nvidia-kernel-* # Move files echo ">>> mv nvidia-graphics-modules-$ngmarch-$GVERS/nvidia-graphics-modules-$ngmarch-$LATEST/* nvidia-graphics-modules-$ngmarch-$GVERS" mv nvidia-graphics-modules-$ngmarch-$GVERS/nvidia-graphics-modules-$ngmarch-$LATEST/* nvidia-graphics-modules-$ngmarch-$GVERS # Clean up echo ">>> rmdir nvidia-graphics-modules-$ngmarch-$GVERS/nvidia-graphics-modules-$ngmarch-$LATEST" rmdir nvidia-graphics-modules-$ngmarch-$GVERS/nvidia-graphics-modules-$ngmarch-$LATEST || exit 127 # Compile for our kernel version. echo ">>> sed -i -e 's/^\(version *:=\).*/\1 '$KVERSMM'/' nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules" sed -i -e 's/^\(version *:=\).*/\1 '$KVERSMM'/' nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules # Update version by adding a changelog entry CHANGELOG="nvidia-graphics-modules-$ngmarch-$GVERS/debian/changelog" echo ">>> mv $CHANGELOG $CHANGELOG.orig" mv $CHANGELOG "$CHANGELOG".orig echo ">>> nvidia_graphics_modules_change_log > $CHANGELOG" nvidia_graphics_modules_change_log > $CHANGELOG echo ">>> cat $CHANGELOG.orig >> $CHANGELOG" cat "$CHANGELOG".orig >> $CHANGELOG echo ">>> rm $CHANGELOG.orig" rm "$CHANGELOG".orig # Fix Provides: and Build-Depends: lines USVERS=`echo "$gvers" | sed -e 's/-/./'` LATEST=`echo "$LATEST" | sed -e 's/\+.*//'` oldrelease=`echo "$LATEST" | sed 's/.*\.//'` nextoldrelease=`echo $oldrelease | awk '{ printf("%02d\n", $0 + 1); }'` release=`echo "$USVERS" | sed 's/.*\.//'` echo "1.release=\"$release\"" nextrelease=`echo $release | awk '{ printf("%02d\n", $0 + 1); }'` usvers=`echo "$LATEST" | sed "s/$oldrelease/$release/"` mmver=`echo "$USVERS" | sed -e "s/\.$release//" -e 's/\./\\./g'` oldmmver=`echo "$LATEST" | sed -e "s/\.$oldrelease//" -e 's/\./\\./g'` echo -n ">>> Replacing $oldmmver.$oldrelease --> $mmver.$release in nvidia-graphics-modules-$ngmarch-$GVERS ... " for f in nvidia-graphics-modules-$ngmarch-$GVERS/control.template \ nvidia-graphics-modules-$ngmarch-$GVERS/debian/control; do sed -i -e "s/$oldmmver\.$oldrelease-[0-9][0-9]*/$mmver.$release-0/g" \ -e "s/$oldmmver\.$oldrelease/$mmver.$release/g" \ -e "s/$oldmmver\.$nextoldrelease-[0-9][0-9]*/$mmver.$nextrelease-0/g" \ -e "s/$oldmmver\.$nextoldrelease/$mmver.$nextrelease/g" \ $f; done echo "done" tar czf nvidia-graphics-modules-$ngmarch""_$GVERS.tar.gz nvidia-graphics-modules-$ngmarch-$GVERS GRAPHICS_MODULES_TAR_GZ=nvidia-graphics-modules-$ngmarch""_$GVERS.tar.gz else echo "Failed to download nvidia-graphics-modules-$ngmarch. Do you have a deb-src line for unstable in your sources.list file?" exit 1 fi fi fi # This is here to allow some hacking in the already extracted directory # without inadvertedly deleting that when the script is re-run. if test -d "nvidia-graphics-modules-$ngmarch-$GVERS"; then echo "Using already existing directory nvidia-graphics-modules-$ngmarch-$GVERS" else TARGETDIR=`tar tzf $GRAPHICS_MODULES_TAR_GZ | grep "^nvidia-graphics-modules-$ngmarch" | head -n 1 | sed 's%/.*%%'` if test "$TARGETDIR" != "nvidia-graphics-modules-$ngmarch-$GVERS"; then echo "$GRAPHICS_MODULES_TAR_GZ does not extract to nvidia-graphics-modules-$ngmarch-$GVERS !?" exit 1 fi echo ">>> tar xzf $GRAPHICS_MODULES_TAR_GZ" tar xzf $GRAPHICS_MODULES_TAR_GZ fi FLAVOURS=`grep '^flavours *:=' nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules | sed -e 's/.*= *//'` if test -z "$FLAVOURS"; then echo "Could not determine flavours" exit 1 fi found=no for flavour in $FLAVOURS; do if test "$ARCH" = "$flavour"; then found=yes fi done if test "$found" = "no"; then echo "Found flavours ($FLAVOURS) but $ARCH is not among them!?" exit 1 fi # Compile for our kernel version. echo ">>> sed -i -e 's/^\(version *:=\).*/\1 '$KVERSMM'/' nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules" sed -i -e 's/^\(version *:=\).*/\1 '$KVERSMM'/' nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules # Only compile our own flavour. echo ">>> sed -i -e 's/^\(flavours *:=\).*/\1 '$ARCH'/' nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules" sed -i -e 's/^\(flavours *:=\).*/\1 '$ARCH'/' nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules FLAVOURS=`grep '^flavours *:=' nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules | sed -e 's/.*= *//'` echo "Compiling for flavours: $FLAVOURS" for flavour in $FLAVOURS; do echo ">>> dpkg --list linux-headers-$KVERSMM-$flavour (quiet)" if ! dpkg --list linux-headers-$KVERSMM-$flavour | tail -n 1 | grep '^ii ' >/dev/null; then echo ">>> apt-get install linux-headers-$KVERSMM-$flavour" if ! sudo apt-get install linux-headers-$KVERSMM-$flavour; then if test -f /lib/modules/$KVERSMM-$flavour/source/include/linux/version.h; then echo "Cannot download linux-headers-$KVERSMM-$flavour, using /lib/modules/$KVERSMM-$flavour/source instead." echo ">>> KSRC=/usr/src/linux-headers-$KVERS" KSRC=/lib/modules/$KVERSMM-$flavour/source else echo "Cannot download linux-headers-$KVERSMM-$flavour and /lib/modules/$KVERSMM-$flavour/source/include/linux/version.h doesn't exist either!" exit 1; fi else echo ">>> KSRC=/usr/src/linux-headers-$KVERS" KSRC=/usr/src/linux-headers-$KVERS fi else echo ">>> KSRC=/usr/src/linux-headers-$KVERS" KSRC=/usr/src/linux-headers-$KVERS fi done # Remove untarring of legacy drivers. echo ">>> sed -i -re 's%^\t(tar[[:space:]]+-?zxf[[:space:]]+/usr/src/nvidia-kernel-legacy-source\.tar\.gz.*)%# \1%' nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules" sed -i -re 's%^\t(tar[[:space:]]+-?zxf[[:space:]]+/usr/src/nvidia-kernel-legacy-source\.tar\.gz.*)%# \1%' \ nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules # Make sure we use the correct KSRC that we just determined. echo ">>> sed -i -re \"s%KSRC=[^ ]*%KSRC=$KSRC%\" nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules" sed -i -re "s%KSRC=[^ ]*%KSRC=$KSRC%" \ nvidia-graphics-modules-$ngmarch-$GVERS/debian/rules if test "$beta" = "yes"; then # Check changelog version. CHANGELOG="nvidia-graphics-modules-$ngmarch-$GVERS/debian/changelog" CHANGELOGVERSION="`cat $CHANGELOG | head -n 1 | sed -e 's/nvidia-graphics-modules-'$ngmarch' (\([^)]*\)).*/\1/'`" if test "$CHANGELOGVERSION" != "$GVERS"; then echo "The changelog version of $CHANGELOG is unequal to $GVERS!" echo "Bailing out." exit 1 fi fi #----------------------------------------------------------------------------------------------- # Collect more data and do some sanity checking if ! test -f $KSRC/include/linux/version.h; then echo "$KSRC/include/linux/version.h: No such file." exit 1 fi CC= test -e $KSRC/.kernelvariables && CC=`grep '^CC *=' $KSRC/.kernelvariables | sed -e 's/^CC *=//' -e 's/$(.*)//' -e 's/ *//g'` test -z "$CC" -a -e $KSRC/debian/buildinfo && CC="gcc-$(cat $KSRC/debian/buildinfo | grep 'gcc version 4\.[0-9]\.' | sed 's/.*gcc version \(4\.[0-9]\).*/\1/')" if test -z "$CC"; then echo "WARNING: Could not determine CC from $KSRC/.kernelvariables or $KSRC/debian/buildinfo" # Guess that it's the same as the running kernel. CC="gcc-$(cat /proc/version | grep 'gcc version 4\.[0-9]\.' | sed 's/.*gcc version \(4\.[0-9]\).*/\1/')" test -n "$CC" || CC="gcc-4.1" fi echo ">>> CC=$CC" WHICHCC=`which $CC` if test -z "$WHICHCC"; then echo "$CC appears not to be installed" exit 1 fi if test -e /etc/ld.so.nohwcap; then echo "WARNING: /etc/ld.so.nohwcap exists! This will cause ld.so to load non-optimized" echo " video driver library versions (if present at all) that in turn" echo " will make X segfault (read: silently exit when you try to start" echo " it, without giving any clue about why)." echo "I'm refusing to even build the drivers until you either remove that" echo "file or edit this script (building of the drivers will namely still" echo "work-- this is just a big warning). If unsure, remove that file." exit 1 fi echo "Using compiler $CC" echo ">>> export KVERS KSRC CC" export KVERS KSRC CC if test "$beta" = "no"; then if test -n "$TARGET"; then echo ">>> apt-get install nvidia-kernel-source=$TARGET" sudo apt-get install nvidia-kernel-source=$TARGET || exit 1 else echo ">>> apt-get install nvidia-kernel-source" sudo apt-get install nvidia-kernel-source || exit 1 fi if test ! -f /usr/src/nvidia-kernel-source.tar.gz -a ! -f /usr/src/nvidia-kernel.tar.bz2; then echo ">>> dpkg --list nvidia-kernel-source (quiet)" if ! dpkg --list nvidia-kernel-source | tail -n 1 | grep '^.i ' >/dev/null; then echo "Please install/fix package nvidia-kernel-source!" else echo "/usr/src/nvidia-kernel-source.tar.gz (old name) nor /usr/src/nvidia-kernel.tar.bz2 (new name) exist?!" fi exit 1 fi else # (Re)construct the source tar ball. echo ">>> apt-get -t unstable source --download-only nvidia-kernel-source" (cd ..; apt-get source -t unstable --download-only nvidia-kernel-source) # Upstream beta version USVERS=`echo "$gvers" | sed -e 's/-/./'` echo ">>> USVERS=\"$USVERS\"" # Find the latest version in the current directory. LATEST=`/bin/ls ../nvidia-graphics-drivers_*.orig.tar.gz | \ sed -re 's/.*nvidia-graphics-drivers_([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.orig\.tar\.gz/\1 000000\2 000000\3 \1.\2.\3/' \ -e 's/.*nvidia-graphics-drivers_([[:digit:]]+)\.([[:digit:]]+)\.orig\.tar\.gz/\1 000000\2 \1.\2/' \ -e 's/ 0*([[:digit:]]{6,})/\1/g' | \ sort -n | tail -n 1 | sed -e 's/.* //'` echo ">>> LATEST=\"$LATEST\"" if test ! -e ../nvidia-graphics-drivers_$LATEST.orig.tar.gz; then echo "Can't find nvidia-graphics-drivers_$LATEST.orig.tar.gz after download." exit 1 fi LATESTVERS=`grep "^Version:.*$LATEST" ../nvidia-graphics-drivers_$LATEST*.dsc | \ sed -re 's/.*[[:space:]]('"$LATEST"'[^[:space:]]*)/\1/' | sort | head -n 1` echo ">>> LATESTVERS=\"$LATESTVERS\"" if test ! -e "../nvidia-graphics-drivers_$LATESTVERS.diff.gz"; then echo "LATESTVERS detected wrongly (can't find \"nvidia-graphics-drivers_$LATESTVERS.diff.gz\")" exit 127 fi if test -e nvidia-graphics-drivers-$USVERS.orig; then if test "$force" = "yes"; then rm -rf nvidia-graphics-drivers-$USVERS.orig else echo "$(pwd)/nvidia-graphics-drivers-$USVERS.orig already exists. Remove first." echo "Use the option --force to REMOVE (previously) generated directories automatically." echo "The reason this isn't done by default is because you might be hacking those directories in order to get things working." echo "If you don't know what this means, then it should be safe to use --force." exit 1 fi fi if test -e nvidia-graphics-drivers-$USVERS; then if test "$force" = "yes"; then rm -rf nvidia-graphics-drivers-$USVERS else echo "$(pwd)/nvidia-graphics-drivers-$USVERS already exists. Remove first." echo "Use the option --force to REMOVE (previously) generated directories automatically." echo "The reason this isn't done by default is because you might be hacking those directories in order to get things working." echo "If you don't know what this means, then it should be safe to use --force." exit 1 fi fi echo ">>> mkdir nvidia-graphics-drivers-$USVERS.orig" mkdir nvidia-graphics-drivers-$USVERS.orig || exit 127 pkg=`ls ../NVIDIA-Linux-$rfarch-$gvers-pkg*.run | sort -n | head -n 1 | sed -e 's/.*-\(pkg[0-9]\)\.run/\1/'` echo ">>> cp ../NVIDIA-Linux-$rfarch-$gvers-$pkg.run nvidia-graphics-drivers-$USVERS.orig/NVIDIA-Linux-$rfarch-$gvers-$pkg.run" || exit 127 cp ../NVIDIA-Linux-$rfarch-$gvers-$pkg.run nvidia-graphics-drivers-$USVERS.orig/NVIDIA-Linux-$rfarch-$gvers-$pkg.run || exit 127 echo ">>> chmod +x nvidia-graphics-drivers-$USVERS.orig/NVIDIA-Linux-$rfarch-$gvers-$pkg.run" chmod +x nvidia-graphics-drivers-$USVERS.orig/NVIDIA-Linux-$rfarch-$gvers-$pkg.run || exit 127 if test "$rfarch" = "x86_64"; then pkgx86=`ls ../NVIDIA-Linux-x86-$gvers-pkg*.run | sort -n | head -n 1 | sed -e 's/.*-\(pkg[0-9]\)\.run/\1/'` if test -e ../NVIDIA-Linux-x86-$gvers-$pkgx86.run; then # if test "$pkg" != "$pkgx86"; then # echo "WARNING: the pkg# of the x86_64 and x86 run files are not the same. This is not a problem but" # echo " the debian/rules makefile involved (erroneously) demands they are. Therefore I'll" # echo " rename NVIDIA-Linux-x86-$gvers-$pkgx86.run to NVIDIA-Linux-x86-$gvers-$pkg.run." # fi echo ">>> cp ../NVIDIA-Linux-x86-$gvers-$pkgx86.run nvidia-graphics-drivers-$USVERS.orig/NVIDIA-Linux-x86-$gvers-$pkgx86.run" || exit 127 cp ../NVIDIA-Linux-x86-$gvers-$pkgx86.run nvidia-graphics-drivers-$USVERS.orig/NVIDIA-Linux-x86-$gvers-$pkgx86.run || exit 127 echo ">>> chmod +x nvidia-graphics-drivers-$USVERS.orig/NVIDIA-Linux-x86-$gvers-$pkg.run" chmod +x nvidia-graphics-drivers-$USVERS.orig/NVIDIA-Linux-x86-$gvers-$pkgx86.run || exit 127 else echo "On amd64 you need both, NVIDIA-Linux-$rfarch-$gvers-pkg*.run as well as NVIDIA-Linux-x86-$gvers-pkg*.run. The latter in order to build the 32bit libs." echo "You can download 32-bit drivers from ftp://download.nvidia.com/XFree86/Linux-x86/." exit 1 fi fi # Create the orig.tar.gz with beta .run file. echo ">>> tar czf nvidia-graphics-drivers-$USVERS.orig.tar.gz nvidia-graphics-drivers-$USVERS.orig" tar czf nvidia-graphics-drivers_$USVERS.orig.tar.gz nvidia-graphics-drivers-$USVERS.orig # We assume that there is only a single patch (by the time there are more # things will be so different that it will break anyway). Apply it. echo ">>> (cd nvidia-graphics-drivers-$USVERS.orig && gzip -dc ../../nvidia-graphics-drivers_$LATESTVERS.diff.gz | patch --silent -p1)" (cd nvidia-graphics-drivers-$USVERS.orig && gzip -dc ../../nvidia-graphics-drivers_$LATESTVERS.diff.gz | patch --silent -p1) # Update the changelogs CHANGELOG="nvidia-graphics-drivers-$USVERS.orig/debian.binary/changelog" echo ">>> mv $CHANGELOG $CHANGELOG.orig" mv $CHANGELOG "$CHANGELOG".orig echo ">>> nvidia_kernel_change_log > $CHANGELOG" nvidia_kernel_change_log > $CHANGELOG echo ">>> cat $CHANGELOG.orig >> $CHANGELOG" cat "$CHANGELOG".orig >> $CHANGELOG echo ">>> rm $CHANGELOG.orig" rm "$CHANGELOG".orig CHANGELOG="nvidia-graphics-drivers-$USVERS.orig/debian/changelog" echo ">>> mv $CHANGELOG $CHANGELOG.orig" mv $CHANGELOG "$CHANGELOG".orig echo ">>> nvidia_graphics_drivers_change_log > $CHANGELOG" nvidia_graphics_drivers_change_log > $CHANGELOG echo ">>> cat $CHANGELOG.orig >> $CHANGELOG" cat "$CHANGELOG".orig >> $CHANGELOG echo ">>> rm $CHANGELOG.orig" rm "$CHANGELOG".orig # Only compile for our architecture echo ">>> sed -i 's/^Architecture:.*/Architecture: '$ngmarch'/' nvidia-graphics-drivers-$USVERS.orig/debian.binary/control.template" sed -i 's/^Architecture:.*/Architecture: '$ngmarch'/' nvidia-graphics-drivers-$USVERS.orig/debian.binary/control.template # Upgrade most of the rest by simply bumping the version number # The sed below is WAY more powerful than really needed - but why make it easy to break it. oldrelease=`echo "$LATEST" | sed 's/.*\.//'` nextoldrelease=`echo $oldrelease | awk '{ printf("%02d\n", $0 + 1); }'` release=`echo "$USVERS" | sed 's/.*\.//'` echo "2.release=\"$release\"" nextrelease=`echo $release | awk '{ printf("%02d\n", $0 + 1); }'` usvers=`echo "$LATEST" | sed "s/$oldrelease/$release/"` mmver=`echo "$USVERS" | sed -e "s/\.$release//" -e 's/\./\\./g'` oldmmver=`echo "$LATEST" | sed -e "s/\.$oldrelease//" -e 's/\./\\./g'` echo -n ">>> Replacing $oldmmver.$oldrelease --> $mmver.$release in nvidia-graphics-drivers-$USVERS.orig/debian ... " if test "$mmver" = "1.0"; then for f in `find nvidia-graphics-drivers-$USVERS.orig/debian -type f ! -name changelog -print`; do sed -i -e "s/\($oldmmver[._-]\)$oldrelease-[0-9][0-9]*/\1$release-0/g" \ -e "s/\($oldmmver[._-]\)$oldrelease/\1$release/g" \ -e "s/\($oldmmver[._-]\)$nextoldrelease-[0-9][0-9]*/\1$nextrelease-0/g" \ -e "s/\($oldmmver[._-]\)$nextoldrelease/\1$nextrelease/g" \ -e "s/pkg0/$pkg/g" \ $f; done else for f in `find nvidia-graphics-drivers-$USVERS.orig/debian -type f ! -name changelog -print`; do sed -i -e "s/$oldmmver[._-]$oldrelease-[0-9][0-9]*/$mmver.$release-0/g" \ -e "s/$oldmmver[._-]$oldrelease/$mmver.$release/g" \ -e "s/$oldmmver[._-]$nextoldrelease-[0-9][0-9]*/$mmver.$nextrelease-0/g" \ -e "s/$oldmmver[._-]$nextoldrelease/$mmver.$nextrelease/g" \ -e "s/pkg0/$pkg/g" \ -e "s/BASE_VERSION=.*/BASE_VERSION=$mmver/" \ -e "s/{BASE_VERSION}-/{BASE_VERSION}./g" \ $f; done fi for f in nvidia-graphics-drivers-$USVERS.orig/debian/control*; do if grep '^Conflicts:.*<< 100\.' $f; then echo "FIXME: Conflicts version too new." exit 1 fi echo ">>> sed -r -i -e \"s/^(Conflicts:.*<<[[:space:]]*)$oldmmver\.[[:digit:]]+-[[:digit:]]+/\1$USVERS-0/\" -e 's/xserver-xorg-core \(>= 2:1.4\)/xserver-xorg-core (>= 2:1.3)/' $f;" sed -r -i -e "s/^(Conflicts:.*<<[[:space:]]*)$oldmmver\.[[:digit:]]+-[[:digit:]]+/\1$USVERS-0/" \ -e 's/xserver-xorg-core \(>= 2:1.4\)/xserver-xorg-core (>= 2:1.3)/' \ $f; done echo "done" echo ">>> sed -r -i -e 's/(RELEASE=([0-9]+\.)*)[0-9]+/\1'$release'/' -e 's/(NEXTVER=([0-9]+\.)*)[0-9]+/\1'$nextrelease'/' -e 's/(DIRNAME=.*-)pkg[0-9]/\1'$pkg'/'" sed -r -i -e 's/(RELEASE=([0-9]+\.)*)[0-9]+/\1'$release'/' \ -e 's/(NEXTVER=([0-9]+\.)*)[0-9]+/\1'$nextrelease'/' \ -e 's/(DIRNAME=.*-)pkg[0-9]/\1'$pkg'/' \ nvidia-graphics-drivers-$USVERS.orig/debian/upstream_info # Newer versions install .so, not .o. # Also don't install libnvidia-cfg.so unless it exists. echo ">>> sed -ri -e 's/(install .*nvidia_drv)\.o/\1.*o/' -e 's%^([[:space:]]*)(install[[:space:]].*[[:space:]])([^[:space:]]*libnvidia-cfg\.so[^[:space:]]*)(.*)%\1test ! -e \3 || \2\3\4%' nvidia-graphics-drivers-$USVERS.orig/debian/rules" sed -ri -e 's/(install .*nvidia_drv)\.o/\1.*o/' \ -e 's%^([[:space:]]*)(install[[:space:]].*[[:space:]])([^[:space:]]*libnvidia-cfg\.so[^[:space:]]*)(.*)%\1test ! -e \3 || \2\3\4%' \ nvidia-graphics-drivers-$USVERS.orig/debian/rules # Don't install cuda stuff unless it exists. #echo ">>> sed -ri -e 's%(install.*cuda.*)%test ! -d \$(dirname)/usr/include/cuda || \1%' nvidia-graphics-drivers-$USVERS.orig/debian/rules" #sed -ri -e 's%(install.*cuda.*)%test ! -d $(dirname)/usr/include/cuda || \1%' nvidia-graphics-drivers-$USVERS.orig/debian/rules # Fix directory name from lib32 to lib. # Create the diff and dsc echo ">>> mv nvidia-graphics-drivers-$USVERS.orig nvidia-graphics-drivers-$USVERS" mv nvidia-graphics-drivers-$USVERS.orig nvidia-graphics-drivers-$USVERS echo ">>> dpkg-source -b nvidia-graphics-drivers-$USVERS" dpkg-source -b nvidia-graphics-drivers-$USVERS # Build the package echo ">>> chmod +x nvidia-graphics-drivers-$USVERS/debian*/rules" chmod +x nvidia-graphics-drivers-$USVERS/debian*/rules cd nvidia-graphics-drivers-$USVERS || exit 127 echo ">>> rm -rf patches" rm -rf patches || exit 127 echo ">>> debian/rules build" debian/rules build || exit 127 # Versions > 100.* are broken in regard to 32-bit. This is a workaround. # First test if we have a broken version: DIRNAME="$(sh debian/upstream_info DIRNAME)" echo "DIRNAME=$DIRNAME" if test "$ARCH" = "amd64" -a ! -e "$DIRNAME/usr/lib32"; then DIRNAME32=$(DEB_BUILD_ARCH=i386 sh debian/upstream_info DIRNAME) DEB_BUILD_ARCH=i386 debian/rules build ln -s ../../$DIRNAME32/usr/lib $DIRNAME/usr/lib32 fi # Setting DEB_BUILD_ARCH here is a bug workaround in debian/rules. # It is needed to install the 32-bit libraries on amd64. echo ">>> fakeroot debian/rules DEB_BUILD_ARCH=$ARCH binary" pwd fakeroot debian/rules DEB_BUILD_ARCH=$ARCH binary || exit 127 # Install the correct sources, we need them below. cd .. echo ">>> sudo dpkg -i nvidia-kernel-source_$USVERS-0_$ngmarch.deb" sudo dpkg -i nvidia-kernel-source_$USVERS-0_$ngmarch.deb # Clean up rm -rf nvidia-graphics-drivers-$USVERS fi echo ">>> mkdir tmp.$$" mkdir tmp.$$ || exit 127 if test -e /usr/src/nvidia-kernel.tar.bz2; then echo ">>> NVIDIA_KERNEL_SOURCE=/usr/src/nvidia-kernel.tar.bz2" NVIDIA_KERNEL_SOURCE=/usr/src/nvidia-kernel.tar.bz2 echo ">>> tar -C tmp.$$ -xjf /usr/src/nvidia-kernel.tar.bz2" tar -C tmp.$$ -xjf /usr/src/nvidia-kernel.tar.bz2 else echo ">>> NVIDIA_KERNEL_SOURCE=nvidia-kernel-source.tar.gz" NVIDIA_KERNEL_SOURCE=/usr/src/nvidia-kernel-source.tar.gz echo ">>> tar -C tmp.$$ -xzf /usr/src/nvidia-kernel-source.tar.gz" tar -C tmp.$$ -xzf /usr/src/nvidia-kernel-source.tar.gz fi KBUILDFILE="tmp.$$/modules/nvidia-kernel/nv/Makefile.kbuild" test -e "$KBUILDFILE" || KBUILDFILE="tmp.$$/modules/nvidia-kernel/Makefile.kbuild" NV_MAJOR_VERSION=`grep 'DNV_MAJOR_VERSION=' "$KBUILDFILE" | sed -re 's/.*DNV_MAJOR_VERSION=([0-9]+) .*/\1/'` NV_MINOR_VERSION=`grep 'DNV_MINOR_VERSION=' "$KBUILDFILE" | sed -re 's/.*DNV_MINOR_VERSION=([0-9]+) .*/\1/'` NV_PATCHLEVEL=`grep 'DNV_PATCHLEVEL=' "$KBUILDFILE" | sed -re 's/.*DNV_PATCHLEVEL=([0-9]+) .*/\1/'` if test -z "$NV_MAJOR_VERSION"; then NV_VERSION_STRING=`grep 'NV_VERSION_STRING=' "$KBUILDFILE" | sed -e 's/^.*NV_VERSION_STRING=\\\\"\([0-9.]*\)\\\\".*$/\1/'` echo "NV_VERSION_STRING=\"$NV_VERSION_STRING\"" grep 'NV_VERSION_STRING=' "$KBUILDFILE" NV_MAJOR_VERSION=`echo "$NV_VERSION_STRING" | sed -e 's/\..*//'` NV_MINOR_VERSION=`echo "$NV_VERSION_STRING" | sed -e 's/^[^.]*\.//' -e 's/[^0-9].*//'` NV_PATCHLEVEL=`echo "$NV_VERSION_STRING" | sed -e 's/^[^.]*\.[^.]*[.]*//' -e 's/[^0-9].*//'` if test -z "$NV_MAJOR_VERSION"; then echo "Could not determine NV_MAJOR_VERSION." rm -rf tmp.$$ exit 1 fi fi rm -rf tmp.$$ if test -z "$NV_MINOR_VERSION"; then echo "Could not determine NV_MINOR_VERSION." exit 1 fi if test -z "$NV_PATCHLEVEL"; then NV_VERSION_STRING="$NV_MAJOR_VERSION.$NV_MINOR_VERSION" else NV_VERSION_STRING="$NV_MAJOR_VERSION.$NV_MINOR_VERSION.$NV_PATCHLEVEL" fi DEB_PATCHLEVEL=`echo "$GVERS" | sed -e 's/.*+//'` if test "$GVERS" != "$NV_VERSION_STRING+$DEB_PATCHLEVEL"; then echo "The nvidia-graphics-modules version ($GVERS) does not match the version of nvidia-kernel-source ($NV_VERSION_STRING)" if test "$beta" = "no"; then echo "Perhaps you forgot to add --runfile=\"$NV_VERSION_STRING\" ?" fi exit 1 fi echo ">>> cd nvidia-graphics-modules-$ngmarch-$GVERS" cd nvidia-graphics-modules-$ngmarch-$GVERS # Fix the name of the tar ball containing the source. if test "$NVIDIA_KERNEL_SOURCE" = "/usr/src/nvidia-kernel.tar.bz2"; then echo ">>> sed -i -re \"s%(.*)tar(.*)z(.*)nvidia-kernel-source\\.tar\\.gz(.*)%\\1tar\\2j\\3nvidia-kernel.tar.bz2\\4%\" debian/rules" sed -i -re "s%(.*)tar(.*)z(.*)nvidia-kernel-source\.tar\.gz(.*)%\1tar\2j\3nvidia-kernel.tar.bz2\4%" debian/rules fi #----------------------------------------------------------------------------------------------- # Rebuild debian/control echo -n "Rebuilding debian/control..." cp debian/control ../control.orig grep "^Source:" ../control.orig > debian/control grep "^Section:" ../control.orig >> debian/control grep "^Priority:" ../control.orig >> debian/control grep "^Maintainer:" ../control.orig >> debian/control echo -n "Build-Depends:" >> debian/control for flavour in $FLAVOURS; do echo -n " linux-headers-$KVERSMM-$flavour," >> debian/control done echo " debhelper (>= 4.0.0), kernel-package, nvidia-kernel-source (>= $NV_VERSION_STRING)" >> debian/control echo "Standards-Version: 3.6.2" >> debian/control rm ../control.orig for flavour in $FLAVOURS; do echo >> debian/control echo "Package: nvidia-kernel-$KVERSMM-$flavour" >> debian/control echo "Architecture: $ngmarch" >> debian/control echo "Description: NVIDIA binary kernel module" >> debian/control done for flavour in $FLAVOURS; do echo >> debian/control echo "Package: nvidia-kernel-2.6-$flavour" >> debian/control echo "Architecture: all" >> debian/control echo "Depends: nvidia-kernel-$KVERSMM-$flavour, linux-image-2.6-$flavour" >> debian/control echo "Description: NVIDIA binary kernel module for 2.6 series compiled for $flavour" >> debian/control echo " This is a metapackage to track the NVIDIA kernel module for" >> debian/control echo " the 2.6 kernel series." >> debian/control echo " ." >> debian/control echo " This package tracks the module compiled against $flavour headers." >> debian/control done echo " done" #----------------------------------------------------------------------------------------------- # Begin building the package echo ">>> fakeroot debian/rules clean" fakeroot debian/rules clean echo ">>> cd ..; dpkg-source -b nvidia-graphics-modules-$ngmarch-$GVERS; cd nvidia-graphics-modules-$ngmarch-$GVERS" cd ..; dpkg-source -b nvidia-graphics-modules-$ngmarch-$GVERS; cd nvidia-graphics-modules-$ngmarch-$GVERS echo ">>> debian/rules build" debian/rules build #----------------------------------------------------------------------------------------------- # Build the binary package echo ">>> fakeroot debian/rules binary" echo PWD = `pwd` if ! fakeroot debian/rules binary; then echo "This probably means that your kernel is too new. Downgrade your kernel for this version to compile." exit 127 fi echo ">>> dpkg-genchanges > ../nvidia-graphics-modules-$ngmarch""_$GVERS.changes" dpkg-genchanges > ../nvidia-graphics-modules-$ngmarch""_$GVERS.changes # Clean up echo ">>> rm -rf $KVERS/nvidia-graphics-modules-$ngmarch-$GVERS" rm -rf $KVERS/nvidia-graphics-modules-$ngmarch-$GVERS echo "Now run:" echo "./install-nvidia-debian --version=$NV_VERSION_STRING --kernel=$KVERS"