medigeek

nvidia postinst file

Mar 18th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.17 KB | None | 0 0
  1. #!/bin/sh
  2. # Copyright (C) 2007-2008 Mario Limonciello
  3. # Copyright (C) 2009 Canonical Ltd
  4. # Authors: Alberto Milone
  5. set -e
  6.  
  7. PACKAGE_NAME=nvidia-current
  8. CVERSION=`dpkg-query -W -f='${Version}' $PACKAGE_NAME | awk -F "-" '{print $1}' | cut -d\: -f2`
  9.  
  10. INIT_SCRIPT="/etc/init/build-$PACKAGE_NAME.conf"
  11. TMP_FILE="/tmp/do_not_build_dkms_module"
  12.  
  13. ARCH=`dpkg --print-architecture`
  14. case $ARCH in
  15.     amd64)
  16.         ARCH="x86_64"
  17.         ;;
  18.     lpia)
  19.         ARCH="i686"
  20.         ;;
  21.     i386)
  22.         ARCH="i686"
  23.         ;;
  24.     *)
  25.         echo "WARNING: unsupported arch: $ARCH"
  26.         ARCH="$ARCH"
  27.         ;;
  28. esac
  29.  
  30. # Check the existence of a kernel named as $1
  31. _is_kernel_name_correct() {
  32.     CORRECT="no"
  33.     KERNEL_NAME=$1
  34.    
  35.     for kernel in /boot/config-*; do
  36.         KERNEL=${kernel#*-}
  37.         if [ "${KERNEL}" = "${KERNEL_NAME}" ]; then
  38.             CORRECT="yes"
  39.             break
  40.         fi
  41.     done
  42.  
  43.     echo $CORRECT
  44. }
  45.  
  46. # Get the most recent kernel on Debian based systems. This keeps
  47. # into account both the version and the ABI. If the current kernel
  48. # is the most recent kernel then the function will print a null string.
  49. _get_newest_kernel_debian() {
  50.     NEWEST_KERNEL=
  51.     NEWEST_VERSION=
  52.     NEWEST_ABI=
  53.    
  54.     for kernel in /boot/config-*; do
  55.         KERNEL=${kernel#*-}
  56.         KERNEL_VERSION=${KERNEL%%-*}
  57.         ABI=${KERNEL#*-}
  58.         ABI=${ABI%%-*}
  59.  
  60.         if [ -z "$NEWEST_KERNEL" ]; then
  61.             # The 1st time get a version which is bigger than $1
  62.             COMPARE_TO=$1
  63.         else
  64.             # Get the biggest version
  65.             COMPARE_TO="$NEWEST_VERSION-$NEWEST_ABI"
  66.         fi
  67.            
  68.         # if $kernel is greater than $COMPARE_TO
  69.         if [ `dpkg --compare-versions "$KERNEL_VERSION-$ABI" gt "$COMPARE_TO" && echo "yes" || \
  70.               echo "no"` = "yes" ]; then
  71.             NEWEST_KERNEL=$KERNEL
  72.             NEWEST_VERSION=$KERNEL_VERSION
  73.             NEWEST_ABI=$ABI
  74.         fi
  75.     done
  76.  
  77.     echo "$NEWEST_KERNEL"
  78. }
  79.  
  80.  
  81. get_newest_kernel() {
  82.     NEWEST_KERNEL=
  83.     # Try Debian first as rpm can be installed in Debian based distros
  84.     if [ -e /usr/bin/dpkg ]; then
  85.         # If DEB based
  86.         CURRENT_KERNEL=$1
  87.         CURRENT_VERSION=${CURRENT_KERNEL%%-*}
  88.         CURRENT_ABI=${CURRENT_KERNEL#*-}
  89.         CURRENT_FLAVOUR=${CURRENT_ABI#*-}
  90.         CURRENT_ABI=${CURRENT_ABI%%-*}
  91.         NEWEST_KERNEL=$(_get_newest_kernel_debian "$CURRENT_VERSION-$CURRENT_ABI")
  92.  
  93.     elif [ `which rpm &>/dev/null` ]; then
  94.         # If RPM based
  95.         NEWEST_KERNEL=$(_get_newest_kernel_rhel)
  96.     fi
  97.  
  98.     # Make sure that kernel name that we extracted corresponds to an installed
  99.     # kernel
  100.     if [ -n "$NEWEST_KERNEL" ] && [ `_is_kernel_name_correct $NEWEST_KERNEL` = "no" ]; then
  101.         NEWEST_KERNEL=
  102.     fi
  103.  
  104.     echo $NEWEST_KERNEL
  105. }
  106.  
  107. case "$1" in
  108.     configure)
  109.         # Deal with alternatives
  110.  
  111.         # Clean up any previous non-multi-arch alternatives
  112.         if [ -n "$(update-alternatives --list gl_conf 2>/dev/null)" ]; then
  113.             set -a $(update-alternatives --list gl_conf 2>/dev/null)
  114.             while [ $# -ge 1 ] && [ "$#" != "configure" ]; do
  115.                 ALTERNATIVE=${1}
  116.                 update-alternatives --remove gl_conf $ALTERNATIVE
  117.                 shift
  118.             done
  119.         fi
  120.  
  121.         # Deal with multi-arch ugliness until dpkg supports multi-arch:
  122.         # - On amd64 we need to install an additional slave link for 32bit vdpau
  123.         #   which - obviously - doesn't exist on i386
  124.         # - It is fine if we get the following:
  125.         #   +  warning: skip creation of /usr/lib32/vdpau/libvdpau_nvidia.so.1 because associated
  126.         #   +  file /usr/lib32/nvidia-current/vdpau/libvdpau_nvidia.so.1 (of link group gl_conf) doesn't exist.
  127.         #
  128.         update-alternatives --force \
  129.             --install /etc/ld.so.conf.d/x86_64-linux-gnu_GL.conf x86_64-linux-gnu_gl_conf /usr/lib/nvidia-current/ld.so.conf 9700 \
  130.             --slave /usr/share/man/man1/nvidia-xconfig.1.gz x86_64-linux-gnu_man_nvidiaxconfig.gz /usr/share/man/man1/alt-nvidia-current-xconfig.1.gz \
  131.             --slave /usr/share/man/man1/nvidia-smi.1.gz x86_64-linux-gnu_nvidia-smi.1.gz /usr/share/man/man1/alt-nvidia-current-smi.1.gz \
  132.             --slave /usr/share/applications/ubuntu-nvidia-settings.desktop x86_64-linux-gnu_nvidia_desktop /usr/share/nvidia-current/ubuntu-nvidia-settings.desktop \
  133.             --slave /usr/bin/nvidia-smi x86_64-linux-gnu_nvidia_smi /usr/lib/nvidia-current/bin/nvidia-smi \
  134.             --slave /usr/bin/nvidia-xconfig x86_64-linux-gnu_nvidia_xconfig /usr/lib/nvidia-current/bin/nvidia-xconfig \
  135.             --slave /usr/bin/nvidia-bug-report.sh x86_64-linux-gnu_nvidia_bug_report /usr/lib/nvidia-current/bin/nvidia-bug-report.sh \
  136.             --slave /usr/lib/XvMCConfig x86_64-linux-gnu_xvmcconfig /usr/lib/nvidia-current/XvMCConfig \
  137.             --slave /etc/xdg/autostart/nvidia-autostart.desktop x86_64-linux-gnu_nvidia-autostart.desktop /usr/share/nvidia-current/nvidia-autostart.desktop \
  138.             --slave /etc/OpenCL/vendors/nvidia.icd x86_64-linux-gnu_nvidia.icd /usr/share/nvidia-current/nvidia.icd \
  139.             --slave /usr/lib/libOpenCL.so x86_64-linux-gnu_libOpenCL.so /usr/lib/nvidia-current/libOpenCL.so \
  140.             --slave /usr/lib32/libOpenCL.so x86_64-linux-gnu_libOpenCL.so_lib32 /usr/lib32/nvidia-current/libOpenCL.so \
  141.             --slave /usr/lib/xorg/modules/drivers/nvidia_drv.so x86_64-linux-gnu_nvidia_drv /usr/lib/nvidia-current/xorg/nvidia_drv.so \
  142.             --slave /etc/modprobe.d/nvidia-graphics-drivers.conf x86_64-linux-gnu_nvidia_modconf /lib/nvidia-current/modprobe.conf \
  143.             --slave /usr/lib/xorg/extra-modules x86_64-linux-gnu_xorg_extra_modules /usr/lib/nvidia-current/xorg \
  144.             --slave /usr/lib/vdpau/libvdpau_nvidia.so.1 x86_64-linux-gnu_libvdpau_nvidia.so.1 /usr/lib/nvidia-current/vdpau/libvdpau_nvidia.so.1 \
  145.             --slave /usr/lib/libvdpau_nvidia.so x86_64-linux-gnu_libvdpau_nvidia.so /usr/lib/nvidia-current/vdpau/libvdpau_nvidia.so \
  146.             --slave /usr/lib32/vdpau/libvdpau_nvidia.so.1 x86_64-linux-gnu_libvdpau_nvidia.so.1_lib32 /usr/lib32/nvidia-current/vdpau/libvdpau_nvidia.so.1 \
  147.             --slave /usr/lib32/libvdpau_nvidia.so x86_64-linux-gnu_libvdpau_nvidia.so_lib32 /usr/lib32/nvidia-current/vdpau/libvdpau_nvidia.so \
  148.             --slave /usr/share/grub-gfxpayload-lists/blacklist/10_$PACKAGE_NAME x86_64-linux-gnu_grub_fb_blacklist /usr/share/nvidia-current/nvidia-current.grub-gfxpayload
  149.  
  150.     # Install just the ld.so.conf.d alternative for the secondary architecture.
  151.     # We need only to ensure that any mesa ld.so.conf.d alternative isn't active.
  152.     update-alternatives --force \
  153.         --install /etc/ld.so.conf.d/i386-linux-gnu_GL.conf i386-linux-gnu_gl_conf /usr/lib/nvidia-current/alt_ld.so.conf 9700
  154.  
  155.         # ldconfig needs to be run immediately as we're changing /etc/ld.so.conf.d/ with
  156.         # alternatives.
  157.         LDCONFIG_NOTRIGGER=y ldconfig
  158.  
  159.         # Trigger gmenu so that the icons will show up in the menu
  160.         dpkg-trigger --by-package=$PACKAGE_NAME gmenucache || true
  161.  
  162.         CURRENT_KERNEL=$(uname -r)
  163.         NEWEST_KERNEL=$(get_newest_kernel "$KERNELS")
  164.  
  165.         ALTERNATIVE=$(readlink /etc/alternatives/x86_64-linux-gnu_gl_conf)
  166.         if [ "$ALTERNATIVE" = "/usr/lib/nvidia-current/ld.so.conf" ]; then
  167.             # Update initramfs so that the blacklist ends up in the initramfs
  168.             update-initramfs -u
  169.            
  170.             if [ -n "$NEWEST_KERNEL" ] && [ ${CURRENT_KERNEL} != ${NEWEST_KERNEL} ]; then
  171.                 # This can fail when dealing with a chroot see LP: #556653
  172.                 update-initramfs -u -k $CURRENT_KERNEL || true
  173.             fi
  174.         fi
  175.  
  176.         # Update the grub gfxpayload blacklist
  177.         if which update-grub-gfxpayload >/dev/null 2>&1; then
  178.             update-grub-gfxpayload
  179.         fi
  180.  
  181.         # If the delayed module build feature is enabled
  182.         # i.e. if $DONT_BUILD_MODULE is set to 1
  183.         # or if $TMP_FILE exists
  184.         if [ "${DONT_BUILD_MODULE}1" -eq "11" ] || [ -e $TMP_FILE ]; then
  185.             # Do not build the module and create
  186.             # the Upstart script which will
  187.             # build the module on next boot
  188.             cat > $INIT_SCRIPT <<EOF
  189. # Warning: This file is autogenerated by $PACKAGE_NAME. All changes to this file will be lost.
  190. start on (starting oem-config
  191.           or starting gdm
  192.           or starting kdm
  193.           or starting xdm
  194.           or starting uxlaunch)
  195. task
  196.  
  197. script
  198.      dkms add -m $PACKAGE_NAME -v $CVERSION
  199.      /usr/lib/dkms/dkms_autoinstaller start || ( rm -f $INIT_SCRIPT && exit 1 )
  200.      modprobe $PACKAGE_NAME || true
  201.      rm -f $INIT_SCRIPT
  202. end script
  203. EOF
  204.         else
  205.             # Build the kernel module
  206.             /usr/lib/dkms/common.postinst $PACKAGE_NAME $CVERSION /usr/share/$PACKAGE_NAME $ARCH $2
  207.             exit $?
  208.         fi
  209.         ;;
  210.  
  211.     abort-upgrade|abort-remove|abort-deconfigure)
  212.     ;;
  213.  
  214.     *)
  215.             echo "postinst called with unknown argument \`$1'" >&2
  216.             exit 1
  217.     ;;
  218. esac
  219.  
  220. # Automatically added by dh_makeshlibs
  221. if [ "$1" = "configure" ]; then
  222.     ldconfig
  223. fi
  224. # End automatically added section
Advertisement
Add Comment
Please, Sign In to add comment