Files
sablink-distro/sys-apps/gpu-detector/files/gpu-configuration
T
lxnay 52f1a22ece add nvidia/ati desktop file copy
git-svn-id: http://svn.sabayonlinux.org/overlay@1347 d7aec97c-591d-0410-af39-a8856400b30a
2007-06-12 23:32:56 +00:00

547 lines
18 KiB
Bash
Executable File

#!/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
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 )
if [ -z "$R7000" ]; then
R7000=$($lspci_output | grep ' VGA ' | grep "Radeon.*7000")
fi
R7200=$($lspci_output | grep ' VGA ' | grep -i "Radeon R100")
if [ -z "$R7200" ]; then
R7200=$($lspci_output | grep ' VGA ' | grep "Radeon.*7200")
fi
R7500=$($lspci_output | grep ' VGA ' | grep -i "Radeon RV200")
if [ -z "$R7500" ]; then
R7500=$($lspci_output | grep ' VGA ' | grep "Radeon.*7500")
fi
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 "ATI.*Radeon.*X700")
RX600=$($lspci_output | grep ' VGA ' | grep -i "ATI.*Radeon.*X600")
RX800=$($lspci_output | grep ' VGA ' | grep -i "ATI.*Radeon.*X8.*0")
RX200=$($lspci_output | grep ' VGA ' | grep -i "ATI.*Radeon.*X.*200M")
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.*")
VIAUNICHROME=$($lspci_output | grep ' VGA ' | grep -i "VIA Tech.*" | grep -i "chrome")
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")
IS_LIVE=$(cat /proc/cmdline | grep " cdroot")
NVIDIA_SETTINGS="/usr/share/applications/nvidia-settings.desktop"
ATI_SETTINGS="/usr/share/applications/amdcccle-ati-drivers.desktop"
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
mv /etc/env.d/09ati /tmp/ &> /dev/null
sed -i '/LIBGL_DRIVERS_PATH/ s/.*//' /etc/profile.env
source /etc/profile &> /dev/null
fix_possible_opengl_misconfiguration xorg-x11
else
echo "I was about to remove proprietary OpenGL libraries"
fi
}
check_if_driver_is_available() {
xdriver=$1
xdriver_exists=$(find /usr/lib/xorg/modules/drivers -name $xdriver\_drv.so)
if [ -n "$xdriver_exists" ]; then
xdriver="0"
else
xdriver="1"
fi
}
check_if_proprietary_driver_system_is_healthy() {
# we should really accept only "nvidia" and "fglrx"
kernel_module=$1
modprobe $kernel_module &> /dev/null
lsmod_output=$(lsmod | grep $kernel_module)
if [ -n "$lsmod_output" ]; then
# now check the opengl subsystem
if [ "$kernel_module" == "nvidia" ]; then
if [ -e "/usr/lib/opengl/nvidia/lib" ]; then
opengl_status=0
else
opengl_status=1
fi
elif [ "$kernel_module" == "fglrx" ]; then
if [ -e "/usr/lib/opengl/ati/lib" ]; then
opengl_status=0
else
opengl_status=1
fi
fi
else
return 1
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
}
disable_dri() {
if [ -z "$dry_run_detected" ]; then
sed -i '/Load.*"dri"/ s/Load/#Load/' $XORGFILE
else
echo "I was about to disable 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!
# it's better to do that anyway
umount /usr/lib/opengl/ati &> /dev/null
umount /usr/lib/opengl/ati &> /dev/null
mv /tmp/09ati /etc/env.d/ &> /dev/null
nice -20 eselect opengl set ati
fi
fi
if [ "$1" = "nvidia" ]; then
if [ "$current_opengl_subsystem" != "nvidia" ]; then
# fix it!
# it's better to do that anyway
umount /usr/lib/opengl/nvidia &> /dev/null
umount /usr/lib/opengl/nvidia &> /dev/null
nice -20 eselect opengl set nvidia
fi
fi
if [ "$1" = "xorg-x11" ]; then
# this MUST be run after remove_proprietary_opengl or inside it
if [ "$current_opengl_subsystem" != "xorg-x11" ]; then
# fix it!
nice -20 eselect opengl set xorg-x11
fi
fi
else
echo "I was about to fix OpenGL subsystem to: "$1", while tue current implementation is "$current_opengl_subsystem
fi
}
copy_nvidia_settings_on_desktop() {
# if it's available, add compiz-settings too
if [ -e "$NVIDIA_SETTINGS" ]; then
for user in `ls /home/`; do
if [ -d "/home/$user/Desktop" ]; then
cp $NVIDIA_SETTINGS /home/$user/Desktop/
chown $user /home/$user/Desktop/$NVIDIA_SETTINGS
fi
done
# also copy in /etc/skel
cp $NVIDIA_SETTINGS /etc/skel/Desktop/ -p
fi
}
copy_ati_settings_on_desktop() {
# if it's available, add compiz-settings too
if [ -e "$ATI_SETTINGS" ]; then
for user in `ls /home/`; do
if [ -d "/home/$user/Desktop" ]; then
cp $ATI_SETTINGS /home/$user/Desktop/
chown $user /home/$user/Desktop/$ATI_SETTINGS
fi
done
# also copy in /etc/skel
cp $ATI_SETTINGS /etc/skel/Desktop/ -p
fi
}
# Code
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 "$VIAUNICHROME" ] || [ -n "$SIS" ] || [ -n "$XGISIS" ] || [ -n "$MATROX" ]; then
remove_proprietary_opengl
fi
enable_dri
fi
if [ "$xdriver" = "nvidia" ]; then
check_if_proprietary_driver_system_is_healthy nvidia
if [ "$opengl_status" == "0" ]; then
fix_possible_opengl_misconfiguration nvidia
copy_nvidia_settings_on_desktop
else
change_xorg_driver nv
fi
fi
if [ "$xdriver" = "fglrx" ]; then
check_if_proprietary_driver_system_is_healthy fglrx
if [ "$opengl_status" == "0" ]; then
fix_possible_opengl_misconfiguration ati
copy_ati_settings_on_desktop
else
change_xorg_driver radeon
fi
fi
if [ "$xdriver" = "vesa" ]; then
sed -i '/Modes/ s/#//' /etc/X11/xorg.conf
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" ] || [ -n "`cat /proc/cmdline | grep 'nvidia=forcefail'`" ]; then
# nvidia=forcefail is only used for debugging...
if [ -z "`cat /proc/cmdline | grep 'nvidia=disablelegacy'`" ]; then
rmmod nvidia &> /dev/null
nv_mod_failed="yes"
else
nv_mod_failed="no"
fi
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
if [ -n "$IS_LIVE" ]; then
# yes, so, check for the legacy drivers
nv_driver_package=$(ls /install-data/drivers/nvidia-drivers-*)
if [ -n "$nv_driver_package" ] && [ -f "$nv_driver_package" ]; 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 garbage
rm /lib/modules/$(uname -r)/video/nvidia.ko -f
rm /lib/nvidia/* -rf
# copy over
# well... unpack roughly here
tar xjf $nv_driver_package -C / &> /dev/null
# create nvidia.ko
ld -m $ld_arch -r -o /lib/modules/$(uname -r)/video/nvidia.ko /lib/nvidia/nvidia.o /lib/nvidia/nvidia.mod.o
# mandatory because we need to re-run the opengl configuration
source /etc/profile
nice -20 eselect opengl set xorg-x11 &> /dev/null
nice -20 eselect opengl set nvidia &> /dev/null
# hope that will work
mkdir -p /lib/nvidia/legacy
touch /lib/nvidia/legacy/running
modprobe nvidia &> /dev/null
check_if_proprietary_driver_system_is_healthy nvidia
if [ "$opengl_status" == "0" ]; then
change_xorg_driver nvidia
fix_possible_opengl_misconfiguration nvidia
copy_nvidia_settings_on_desktop
else
change_xorg_driver nv
fi
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
check_if_proprietary_driver_system_is_healthy nvidia
if [ "$opengl_status" == "0" ]; then
change_xorg_driver nvidia
fix_possible_opengl_misconfiguration nvidia
copy_nvidia_settings_on_desktop
else
change_xorg_driver nv
fi
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 "$RX800" ] || [ -n "$RX600" ] || [ -n "$R9600" ] || [ -n "$RX200" ]; 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
check_if_proprietary_driver_system_is_healthy fglrx
if [ "$opengl_status" == "0" ]; then
change_xorg_driver fglrx
fix_possible_opengl_misconfiguration ati
enable_dri
copy_ati_settings_on_desktop
else
change_xorg_driver radeon
enable_dri
remove_proprietary_opengl
fi
nice -20 env-update &> /dev/null
source /etc/profile
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 "$VIAUNICHROME" ]; then
# Check if the openchrome driver exists
check_if_driver_is_available openchrome
if [ "$xdriver" = "1" ]; then
change_xorg_driver via
enable_dri
remove_proprietary_opengl
echo -e "\t Display Driver: VIA Technologies"
else
change_xorg_driver openchrome
enable_dri
remove_proprietary_opengl
echo -e "\t Display Driver: VIA Technologies UniChrome Chipset"
fi
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)"
sed -i '/Modes/ s/#//' /etc/X11/xorg.conf
fi