#!/bin/sh## Loads drivers for specified modaliases, skipping disabled display drivers# that would cause conflicts.## Copyright (c) 2010 Anssi Hannula <anssi.hannula@ıki.fi>## Licensed under terms of GPLv2 or later.gl_inode=xorg_drivers=check_gl() { local alt_inode="$(stat -L -c%i $1 2>/dev/null)" [ -n "$alt_inode" ] || return 1 [ -n "$gl_inode" ] || gl_inode="$(stat -L -c%i /etc/alternatives/gl_conf 2>/dev/null)" [ "$alt_inode" = "$gl_inode" ] || return 1 return 0}check_xorg() { local driver="$1" local conflicts="$2" local explicit_only="$3" if [ -z "$xorg_drivers" ]; then xorg_drivers="$(awk -F'"' -vORS=' ' -vIGNORECASE=1 ' /^[[:space:]]+*section[[:space:]]+"device"/ { device=1 } /endsection/ { device=0 } /^[[:space:]]*driver[[:space:]]*".*"/ { if (device) drivers[$2]=$2 } END { for (driver in drivers) print driver }')" xorg_drivers="$(/bin/grep -i "^\s*driver\s\+\"\($interesting_xorg_drivers\)\"" /etc/X11/xorg.conf 2>/dev/null)" [ -n "$xorg_drivers" ] || xorg_drivers="-" fi case " $xorg_drivers " in *" $driver "*) # driver is explicitely selected - ok to load return 0 ;; $conflicts) # conflicting driver is selected - do not load return 1 ;; esac # no driver is selected - load unless explicit_only is set return $explicit_only}for mod in $(/sbin/modprobe -bqvn "$1"); do [ "$mod" = "insmod" ] && continue modulename="${mod##*/}" modulename="${modulename%%.*}" echo $modulename case "$modulename" in i915) # there are no conflicting drivers, so i915 is safe to load # unless using vesa check_xorg i915 "* vesa *" 0 || continue ;; radeon) check_gl /etc/ld.so.conf.d/GL/standard.conf || continue # we can only load radeon when explicitely set - even if a conflicting # driver isn't selected, it could be that such a driver is going to be # installed during the boot sequence check_xorg radeon . 1 || continue ;; nouveau) check_gl /etc/ld.so.conf.d/GL/standard.conf || continue check_xorg nouveau . 1 || continue ;; fglrx) check_gl /etc/ld.so.conf.d/GL/ati.conf || continue ;; nvidiafb) # this is only reached if nvidiafb is manually unblacklisted, in which # case we assume the driver is wanted for some reason ;; nvidia*) check_gl /etc/$modulename/ld.so.conf || continue ;; *) continue ;; esac /sbin/modprobe -b "$modulename" && exit 0done/sbin/modprobe -b "$1"