#!/bin/sh # a script to update Driver "..." in xorg.conf as seen on PCI # by Michael Shigorin , 2005, 2006 # use and modify freely # thanks for tips to Sergey Vlasov # and Sergey Bolshakov # init: avoid vesa but still have it as a fallback VESA="Generic VESA compatible" CARD= DRIVER="vesa" debug() { [ -n "$DEBUG" ] && echo $0: $* >&2 } error() { echo $0: $* >&2; exit 1 } ( which x11createconfig && which x11setupdrv && \ which x11setupdrv ) >&/dev/null || { error "needed utilities missing" } # put it to function since |while will go subshell # and won't influence main process' vars cards() { x11createconfig -c \ | grep -v "$VESA" \ | awk -F: '/^card:/ { print $2; }' \ | while read type; do debug "considering non-vesa [$type]" [ -n "$type" ] && { [ -n "$CARD" ] && { echo "$0: warning, overriding already acquired $CARD!" >&2 } CARD="$type" echo "$CARD" } || echo "$0: hmm, empty card type in x11createconfig output?" >&2 done } # read bus info for second ATI Radeon head, if any # note that we drop function and force it to 0 secondary() { lspci -d 1002: \ | grep Secondary \ | while read bus device function rest; do busid="$bus:$device" done debug "secondary BusID: ${busid:-1:0}:0" echo ${busid:-1:0}:0 } # x11setupdrv -s doesn't support multihead yet # (actually all of this is a relatively quick hack # to plug a hole with automatic more-or-less setup # right at bootup...) -- taking presumably primary # device available on higher numbered PCI bus CARD=`cards | tail -1` debug "card: [$CARD]" [ -n "$CARD" ] && { xdriver=`vcardinfo "$CARD" | awk '/^xdriver\t/ { print $2; exit; }'` || { error "pciscan failed" } # another one for Radeon 9550 and others set up with fglrx // mike on 20070312 [ "$xdriver" = "fglrx" ] && { debug "WARNING: fixing up preferred ATI driver (fglrx->ati)" xdriver="ati" } [ -n "$xdriver" ] && DRIVER="$xdriver" } || { # is it some fancy new card not in hwdatabase yet? debug "WARNING: an empty CARD!" # NVIDIA might also be onboard pciscan -c 003 \ | grep -q 'nVidia Corporation.*VGA compatible controller' \ && { debug "WARNING: some unknown NVIDIA videocard found, trying to use nvidia..." DRIVER="nvidia" } # ATI has less chance to be onboard, rather dualhead pciscan -c 003 \ | grep -q 'ATI Technologies Inc.*VGA compatible controller' \ && { debug "WARNING: some unknown ATI videocard found, trying to use ati..." DRIVER="ati" } # else defaults to vesa } debug "driver: [$DRIVER]" CURRENT=`x11setupdrv -d --nosetup | sed 's/driver name: //'` || { error "x11setupdrv failed" } debug "current: [$CURRENT]" [ "$DRIVER" == "$CURRENT" ] && { debug "nothing to modify, driver is the same" exit 0 # nothing to be done } debug ">> setting driver to [$DRIVER]" x11setupdrv -s "$DRIVER" || { error "x11setupdrv failed to modify configuration" } busid=`secondary` [ -n "$busid" ] && subst \ "s/\\(^[[:space:]]*BusID[[:space:]]*\"PCI:\\)1:0:0\"/\\1$busid\"/" \ /etc/X11/xorg.conf