#!/bin/sh XORGFILE="/etc/X11/xorg.conf" dry_run_detected=$(echo $@ | grep "dry-run") lspci_output=$(echo $@ | grep "with-lspci=") if [ -n "$lspci_output" ]; then lspci_output="echo $@" lsusb_output="echo $@" else if [ -e /sbin/lspci ]; then lspci_output="/sbin/lspci" else lspci_output="/usr/sbin/lspci" fi fi remove_proprietary_opengl() { if [ -z "$dry_run_detected" ]; then # Fix for DRI accel mount -t tmpfs none /usr/lib/opengl/ati &> /dev/null mount -t tmpfs none /usr/lib/opengl/nvidia &> /dev/null # FIX For fscking ATI env.d file rm -f /etc/env.d/*ati &> /dev/null sed -i '/LIBGL_DRIVERS_PATH s/.*//' /etc/profile.env nice -20 source /etc/profile &> /dev/null nice -20 eselect opengl set xorg-x11 else echo "I was about to remove proprietary OpenGL libraries" fi } change_xorg_driver() { if [ -z "$dry_run_detected" ]; then sed -i '/do not remove vesa/ s/".*"/"'$1'"/' $XORGFILE else echo "I was about to change X.Org driver to: "$1 fi } enable_dri() { if [ -z "$dry_run_detected" ]; then sed -i '/"dri"/ s/#//' $XORGFILE else echo "I was about to Enable DRI" fi } fix_possible_opengl_misconfiguration() { current_opengl_subsystem=$(eselect opengl show) if [ -z "$dry_run_detected" ]; then if [ "$1" = "ati" ]; then if [ "$current_opengl_subsystem" != "ati" ]; then # fix it! nice -20 eselect opengl set ati fi fi if [ "$1" = "nvidia" ]; then if [ "$current_opengl_subsystem" != "nvidia" ]; then # fix it! nice -20 eselect opengl set nvidia fi fi else echo "I was about to fix OpenGL subsystem to: "$1", while tue current implementation is "$current_opengl_subsystem fi } NEOMAGIC=$($lspci_output | grep ' VGA ' | grep -i 'neomagic') MACH64=$($lspci_output | grep ' VGA ' | grep -i 'mach64' ) SAVAGE=$($lspci_output | grep ' VGA ' | grep -i 'savage' ) VIRGE=$($lspci_output | grep ' VGA ' | grep -i 'Virge' ) CYRIX=$($lspci_output | grep ' VGA ' | grep -i 'cyrix' ) I128=$($lspci_output | grep ' VGA ' | grep -i 'i128' ) I740=$($lspci_output | grep ' VGA ' | grep -iE ' intel.*74' ) RENDITION=$($lspci_output | grep ' VGA ' | grep -i 'rendition' ) SILICONMOTION=$($lspci_output | grep ' VGA ' | grep -iE ' silicon.*motion' ) TSENG=$($lspci_output | grep ' VGA ' | grep -i 'tseng') IGRANTSDALE=$($lspci_output | grep ' VGA ' | grep -i "Intel Corp.*915.*") INTEL=$($lspci_output | grep ' VGA ' | grep -i "Intel Corp") I830=$($lspci_output | grep ' VGA ' | grep -i "Intel Corp.*82830.*") I845=$($lspci_output | grep ' VGA ' | grep -i "Intel Corp.*845.*") I855=$($lspci_output | grep ' VGA ' | grep -i "Intel Corp.*855.*") V3DFX=$($lspci_output | grep ' VGA ' | grep -i "3Dfx Interactive" ) I915=$($lspci_output | grep ' VGA ' | grep -i "Intel Corp.*915.*") I945=$($lspci_output | grep ' VGA ' |grep -i "Intel Corp.*945.*" || $lspci_output | grep ' VGA ' | grep -i "Intel Corp.*940.*" ) TRIDENT=$($lspci_output | grep ' VGA ' | grep Trident) NVIDIA=$($lspci_output | grep ' VGA ' | grep -i "nVidia") NVIDIATNT=$($lspci_output | grep ' VGA ' | grep -i "RIVA TNT") ATI=$($lspci_output | grep ' VGA ' | grep ATI) R7000=$($lspci_output | grep ' VGA ' | grep R100 || $lspci_output | grep ' VGA ' | grep RV100 ) R7200=$($lspci_output | grep ' VGA ' | grep -i "Radeon R100") R7500=$($lspci_output | grep ' VGA ' | grep -i "Radeon RV200") R2XX=$($lspci_output | grep ' VGA ' | grep -i "ATi Tech" |grep -i "RV2.*" || $lspci_output | grep ' VGA ' | grep -i "ATi Tech" |grep -i "R2.*") R1XX=$($lspci_output | grep ' VGA ' | grep -i "ATi Tech" |grep -i "RV1.*" || $lspci_output | grep ' VGA ' | grep -i "ATi Tech" |grep -i "R1.*") RX700=$($lspci_output | grep ' VGA ' | grep -i "Radeon Mobility X700") R9600=$($lspci_output | grep ' VGA ' | grep -i 'ATI Technologies .* RV350' ) RAGE128=$($lspci_output | grep ' VGA ' | grep -i "Rage 128") SIS=$($lspci_output | grep ' VGA ' | grep -i "SiS" || $lspci_output | grep ' VGA ' | grep "Silicon Integrated Systems") XGISIS=$($lspci_output | grep ' VGA ' | grep -i XGI | grep Volari) # SiS driver only supports Z7/V3/V5/V8 - the future new xf86-video-xgi driver will support the rest of the family SISUSB=$(if [ -e /sys/module/sisusbvga ]; then echo sisusb; fi) # udev will take care of the kernel module VMWARE=$($lspci_output | grep ' VGA ' | grep VMWare || $lspci_output | grep ' VGA ' | grep VMware ) VIRGE=$($lspci_output | grep ' VGA ' | grep -i "S3.*virge") VIA=$($lspci_output | grep ' VGA ' | grep -i "VIA Tech.*") MATROX=$($lspci_output | grep ' VGA ' | grep -i Matrox) CIRRUS=$($lspci_output | grep ' VGA ' | grep -i Cirrus) NOPROP=$(cat /proc/cmdline | grep "noproprietary") LEGACY=$(cat /proc/cmdline | grep "legacy") if [ -z "$ATI" ]; then if [ -z "$dry_run_detected" ]; then # FIX For fscking ATI env.d file rm -f /etc/env.d/*ati &> /dev/null env-update && source /etc/profile &> /dev/null else echo "ATI cards not detected, skipping env.d files removal" fi fi current_arch=$(uname -m) if [ "$current_arch" == "x86_64" ]; then ld_arch="elf_x86_64" elif [ "$current_arch" == "i686" ]; then ld_arch="elf_i386" fi # Check for xdriver= is_there_xdriver=$(cat /proc/cmdline | grep "xdriver=") if [ -n "$is_there_xdriver" ]; then for word in `cat /proc/cmdline`; do case $word in xdriver=*) xdriver=$(echo $word | cut -d= -f 2) change_xorg_driver $xdriver if [ -z "$NVIDIA" ]; then if [ -n "$R7000" ] || [ -n "$R7200" ] || [ -z "$R7500" ] || [ -n "$R2XX" ] || [ -n "$R1XX" ] || [ -n "$INTEL" ] || [ -n "$VIA" ] || [ -n "$SIS" ] || [ -n "$XGISIS" ] || [ -n "$MATROX" ]; then remove_proprietary_opengl fi enable_dri fi if [ "$xdriver" = "nvidia" ]; then fix_possible_opengl_misconfiguration nvidia fi if [ "$xdriver" = "fglrx" ]; then fix_possible_opengl_misconfiguration ati fi ;; esac done exit 0 fi if [ -n "$SISUSB" ]; then # SiS USB Video dongle will take the priority change_xorg_driver sisusb enable_dri remove_proprietary_opengl echo -e "\t Display Driver: SiS USB" exit 0 fi if [ -n "$NVIDIA" ]; then if [ -n "$NOPROP" ] || [ -n "$LEGACY" ]; then change_xorg_driver nv echo -e "\t Display Driver: NVIDIA (OpenSource)" else modprobe nvidia &> /dev/null if [ "$?" != "0" ]; then nv_mod_failed="yes" else nv_mod_failed="no" fi # Check for errors if [ "$nv_mod_failed" == "yes" ]; then if [ -z "$dry_run_detected" ]; then # ok, maybe unsupported # check if we are running in the live mode is_live=$(cat /proc/cmdline | grep cdroot) if [ -n "$is_live" ]; then # yes, so, check for the legacy drivers if [ -e "/lib/modules/nvidia/legacy" ]; then # prepare legacy drivers if [ -e "/usr/bin/qlist" ]; then qlist -e nvidia-drivers | xargs rm -rf rm -rf /var/db/pkg/x11-drivers/nvidia-drivers-* sed -i '/.*nvidia-drivers.*/d' /var/lib/portage/world else emerge -C nvidia-drivers &> /dev/null fi # remove old nvidia.ko rm /lib/modules/$(uname -r)/video/nvidia.ko -f # copy over cp /lib/nvidia/legacy/* / -Rp &> /dev/null # create nvidia.ko ld -m $ld_arch -r -o /lib/modules/$(uname -r)/video/nvidia.ko /lib/nvidia/legacy/nvidia.o /lib/nvidia/legacy/nvidia.mod.o # set nvidia nice -20 source /etc/profile nice -20 eselect opengl set nvidia &> /dev/null # hope that will work touch /lib/nvidia/legacy/running change_xorg_driver nvidia fix_possible_opengl_misconfiguration nvidia else # revert to nv change_xorg_driver nv echo -e "\t Display Driver: NVIDIA (OpenSource) - Legacy drivers cannot be deployed" fi else # revert to nv change_xorg_driver nv echo -e "\t Display Driver: NVIDIA (OpenSource) - Proprietary drivers can't be loaded - unsupported video card?" fi else echo "NVIDIA non-legacy drivers modprobe failed, I was about to try nvidia-legacy ones" fi else # ok, configure the standard nvidia driver change_xorg_driver nvidia fix_possible_opengl_misconfiguration nvidia echo -e "\t Display Driver: NVIDIA (Proprietary)" fi fi elif [ -n "$RAGE128" ]; then change_xorg_driver r128 enable_dri remove_proprietary_opengl echo -e "\t Display Driver: ATI Rage 128" elif [ -n "$V3DFX" ]; then change_xorg_driver tdfx enable_dri remove_proprietary_opengl sed -i '/DefaultDepth/ s/24/16/' $XORGFILE echo -e "\t Display Driver: 3Dfx Video Card" elif [ -n "$I855" ] || [ -n "$I915" ] || [ -n "$I945" ] || [ -n "$I845" ] || [ -n "$IGRANTSDALE" ] || [ -n "$I830" ]; then change_xorg_driver i810 enable_dri remove_proprietary_opengl echo -e "\t Display Driver: Intel Video Card" elif [ -n "$INTEL" ]; then # unfortunately, I cannot detect the Intel card correctly, so I am trying to force i810 at least change_xorg_driver i810 enable_dri remove_proprietary_opengl echo -e "\t Display Driver: Intel Video Card - not detected with precision, trying i810 driver" elif [ -n "$ATI" ] || [ -n "$RX700" ] || [ -n "$R9600" ]; then if [ -n "$NOPROP" ] || [ -n "$LEGACY" ]; then change_xorg_driver radeon enable_dri remove_proprietary_opengl sed -i '/ColorTiling/ s/#//' $XORGFILE sed -i '/EnablePageFlip/ s/#//' $XORGFILE echo -e "\t Display Driver: ATI (OpenSource)" else if [ -z "$R7000" ] && [ -z "$R7200" ] && [ -z "$R7500" ] && [ -z "$R2XX" ] && [ -z "$R1XX" ]; then modprobe fglrx &> /dev/null lsmod_ati=$(lsmod | grep fglrx) if [ -n "$lsmod_ati" ];then change_xorg_driver fglrx fix_possible_opengl_misconfiguration ati enable_dri echo -e "\t Display Driver: ATI (Proprietary)" else change_xorg_driver radeon enable_dri remove_proprietary_opengl sed -i '/ColorTiling/ s/#//' /etc/X11/xorg.conf sed -i '/EnablePageFlip/ s/#//' /etc/X11/xorg.conf echo -e "\t Display Driver: ATI (OpenSource) - Proprietary drivers can't be loaded" fi else change_xorg_driver radeon enable_dri remove_proprietary_opengl echo -e "\t Display Driver: ATI (OpenSource)" fi fi elif [ -n "$SIS" ] || [ -n "$XGISIS" ]; then change_xorg_driver sis enable_dri remove_proprietary_opengl echo -e "\t Display Driver: SiS/XGI" elif [ -n "$VMWARE" ]; then change_xorg_driver vmware enable_dri # Uncomment "Modes" sed -i '/Modes/ s/#//g' /etc/X11/xorg.conf sed -i '/HorizSync/ s/#//g' /etc/X11/xorg.conf sed -i '/VertRefresh/ s/#//g' /etc/X11/xorg.conf echo -e "\t Display Driver: VMWARE" elif [ -n "$SAVAGE" ]; then change_xorg_driver savage enable_dri remove_proprietary_opengl echo -e "\t Display Driver: Savage" elif [ -n "$VIRGE" ]; then change_xorg_driver s3virge enable_dri remove_proprietary_opengl echo -e "\t Display Driver: S3 Virge" elif [ -n "$MATROX" ]; then change_xorg_driver mga enable_dri remove_proprietary_opengl echo -e "\t Display Driver: MATROX" elif [ -n "$VIA" ]; then change_xorg_driver via enable_dri remove_proprietary_opengl echo -e "\t Display Driver: VIA Technologies" elif [ -n "$CIRRUS" ]; then change_xorg_driver cirrus #enable_dri echo -e "\t Display Driver: Cirrus Logic" elif [ -n "$TRIDENT" ]; then change_xorg_driver trident #enable_dri echo -e "\t Display Driver: Cirrus Logic" else echo -e "\t Display Driver: VESA (no supported card detected)" fi