#!/bin/bash echo "Test for acpi_call/vgaswitcheroo" modprobe bbswitch &>/dev/null modprobe acpi_call &>/dev/null if [ -f /proc/acpi/bbswitch ]; then echo "bbswitch is OK! ;-)" elif [ -f /proc/acpi/call ]; then echo "acpi_call is OK! ;-)" elif [ -f /sys/kernel/debug/vgaswitcheroo/switch ]; then echo "vgaswitcheroo is OK! ;-)" else echo "No bbswitch/acpi_call/vgaswitcheroo found. Please configure/install one of them! ;-(" exit -1 fi echo "Test for nVidia driver" snail.nv_pwr_on && snail.nv_pwr_off if [ 0 -eq $? ]; then echo "nVidia driver is OK! ;-)" else echo "Test failed ;-(" echo "Probably you need to install standart nVidia driver or make a bug report..." exit -1 fi echo "Test for dmidecode utility..." which dmidecode &>/dev/null if [ 0 -eq $? ]; then echo "dmidecode utility is OK! ;-)" else echo "Please install dmidecode and run the script again." exit -1 fi echo "Detecting your distribution..." DISTRIB_ID= DISTRIB_DESCRIPTION= DISTRIB_RELEASE= DISTRIB_CODENAME= if [ -f /etc/gentoo-release ]; then DISTRIB_ID=gentoo DISTRIB_DESCRIPTION=`cat /etc/gentoo-release` DISTRIB_RELEASE=${DISTRIB_DESCRIPTION##* } DISTRIB_CODENAME=gentoo elif [ -f /etc/lsb-release ]; then DISTRIB_ID=`grep ^DISTRIB_ID /etc/lsb-release | cut -d= -f2` DISTRIB_RELEASE=`grep ^DISTRIB_RELEASE /etc/lsb-release | cut -d= -f2` DISTRIB_CODENAME=`grep ^DISTRIB_CODENAME /etc/lsb-release | cut -d= -f2` DISTRIB_DESCRIPTION=`grep ^DISTRIB_DESCRIPTION /etc/lsb-release | cut -d= -f2` elif [ -f /etc/debian_version ]; then DISTRIB_ID=debian DISTRIB_RELEASE=`cat /etc/debian_version` DISTRIB_DESCRIPTION=`cat /etc/issue.net` DISTRIB_CODENAME=${DISTRIB_RELEASE%%/*} elif [ -f /etc/slax_version ]; then DISTRIB_ID=slax DISTRIB_DESCRIPTION=`cat /etc/slax_version` elif [ -f /etc/arch-release ]; then DISTRIB_ID=arch DISTRIB_DESCRIPTION=`cat /etc/arch-release` elif [ -f /etc/slackware_version ]; then DISTRIB_ID=slackware DISTRIB_DESCRIPTION=`cat /etc/slackware_version` elif [ `which lsb_release &>/dev/null` ]; then DISTRIB_ID=`lsb_release | grep '^Distributor' | sed 's~[^:]*:~~' | tr 'A-Z' 'a-z'` DISTRIB_DESCRIPTION=`lsb_release | grep '^Description' | sed 's~[^:]*:~~'` DISTRIB_RELEASE=`lsb_release | grep '^Release' | sed 's~[^:]*:~~'` DISTRIB_CODENAME=`lsb_release | grep '^Codename' | sed 's~[^:]*:~~'` elif [ -f /etc/os-release ]; then DISTRIB_ID=`grep '^ID=' /etc/os-release | cut -d'=' -f2` DISTRIB_DESCRIPTION=`grep '^PRETTY_NAME=' /etc/os-release | cut -d'=' -f2` DISTRIB_RELEASE=`grep '^VERSION_ID=' /etc/os-release | cut -d'=' -f2` DISTRIB_CODENAME=`grep '^NAME=' /etc/os-release | cut -d'=' -f2` elif [ -f /etc/fedora-release ]; then DISTRIB_ID=fedora DISTRIB_DESCRIPTION=`cat /etc/fedora-release` DISTRIB_RELEASE=${DISTRIB_DESCRIPTION% *} DISTRIB_RELEASE=${DISTRIB_RELEASE##* } DISTRIB_CODENAME=${DISTRIB_DESCRIPTION##*\(} DISTRIB_CODENAME=${DISTRIB_CODENAME%%\)*} elif [ -f /etc/issue ]; then DISTRIB_ID=`cut -d" " -f1 /etc/issue | head -n1` DISTRIB_RELEASE=`cut -d" " -f2 /etc/issue | head -n1` else DISTRIB_DESCRIPTION=`cat /etc/*release* | head -n1` DISTRIB_ID=`echo ${DISTRIB_DESCRIPTION%% *} | tr 'A-Z' 'a-z'` DISTRIB_RELEASE=`echo ${DISTRIB_DESCRIPTION%% *} | sed 's~[^0-9]\+\([0-9\.]\+\).*~\1~'` DISTRIB_CODENAME=$DISTRIB_ID fi [ "" == "$DISTRIB_ID" ] && echo 'GNU/Linux distribution not recognized, sorry! Please post a bug!' && exit -1 echo 'Detected distribution:' echo "DISTRIB_ID=$DISTRIB_ID" echo "DISTRIB_DESCRIPTION=$DISTRIB_DESCRIPTION" echo "DISTRIB_RELEASE=$DISTRIB_RELEASE" echo "DISTRIB_CODENAME=$DISTRIB_CODENAME" SNAIL_INIT_D_PATH=/usr/share/snail/init.d echo "Copying system init scripts (SysV/OpenRC/Systemd), start snail-watcher, configuring kernel modules and OpenGL libraries" case "$DISTRIB_ID" in "gentoo") cp -f $SNAIL_INIT_D_PATH/snail-watcher.openrc /etc/init.d/snail-watcher cp -f $SNAIL_INIT_D_PATH/snail-xserver.openrc /etc/init.d/snail-xserver eselect rc delete snail-xserver boot default eselect rc delete snail-watcher boot eselect rc add snail-watcher default eselect rc stop snail-xserver eselect rc restart snail-watcher grep bbswitch /etc/conf.d/modules || echo 'modules="${modules} bbswitch"' >> /etc/conf.d/modules grep acpi_call /etc/conf.d/modules || echo 'modules="${modules} acpi_call"' >> /etc/conf.d/modules eselect opengl set xorg-x11 for arch in 32bit 64bit; do for chip in i915 i965 r300 r600 sw; do eselect mesa set $arch $chip classic &>/dev/null; done; done ln -sf /usr/lib/opengl/nvidia/lib/libGL.so.[0-9][0-9]* /usr/lib/snail/libGL.so.1 ln -sf /usr/lib32/opengl/nvidia/lib/libGL.so.[0-9][0-9]* /usr/lib/snail/lib32/libGL.so ln -sf /usr/lib/xorg/modules/libfb.so /usr/lib/snail/libfb.so ln -sf /usr/lib/xorg/modules/libwfb.so /usr/lib/snail/libwfb.so ln -sf /usr/lib/opengl/nvidia/extensions/libglx.so.[0-9][0-9]* /usr/lib/snail/libglx.so ln -sf /usr/lib/opengl/nvidia/lib/libnvidia-tls.so.[0-9][0-9]* /usr/lib/snail/ ln -sf /usr/lib32/opengl/nvidia/lib/libnvidia-tls.so.[0-9][0-9]* /usr/lib/snail/lib32/libnvidia-tls.so ln -sf /usr/lib/xorg/modules/drivers/nvidia_drv.so /usr/lib/snail/nvidia_drv.so ;; "debian") cp -f $SNAIL_INIT_D_PATH/snail-watcher.sysv /etc/init.d/snail-watcher cp -f $SNAIL_INIT_D_PATH/snail-xserver.sysv /etc/init.d/snail-xserver update-rc.d snail-xserver remove update-rc.d snail-watcher defaults /etc/init.d/snail-xserver stop /etc/init.d/snail-watcher start grep '^bbswitch$' /etc/modules || echo bbswitch >> /etc/modules grep '^acpi_call$' /etc/modules || echo acpi_call >> /etc/modules case "$DISTRIB_RELEASE" in 6.?.?) # nVidia driver installed from Debian repositories if [ -f /usr/lib/nvidia/diversions/libGL.so.1 ]; then ln -sf /usr/lib/xorg/modules/libfb.so /usr/lib/snail/libfb.so ln -sf /usr/lib/xorg/modules/libwfb.so /usr/lib/snail/libwfb.so ln -sf /usr/lib/xorg/modules/drivers/nvidia_drv.so /usr/lib/snail/nvidia_drv.so # rm -f /usr/lib/xorg/modules/extensions/libglx.so ln -sf /usr/lib/xorg/modules/extensions/libglx.so.[0-9][0-9]* /usr/lib/snail/libglx.so ln -sf /usr/lib/libGL.so.[0-9][0-9]* /usr/lib/snail/libGL.so.1 # apt-get install --reinstall xserver-xorg-core # rm -f /etc/alternatives/libGL.so.1 # ln -s /usr/lib/nvidia/diversions/libGL.so.1 /etc/alternatives # nVidia driver was installed by NVIDIA-installer...run else ln -sf /usr/lib/xorg/modules/libfb.so /usr/lib/snail/libfb.so ln -sf /usr/lib/xorg/modules/libwfb.so /usr/lib/snail/libwfb.so ln -sf /usr/lib/xorg/modules/drivers/nvidia_drv.so /usr/lib/snail/nvidia_drv.so ln -sf /usr/lib/xorg/modules/extensions/libglx.so.[0-9][0-9]* /usr/lib/snail/libglx.so ln -sf /usr/lib/libGL.so.[0-9][0-9]* /usr/lib/snail/libGL.so.1 rm -f /usr/lib/libGL.so /usr/lib/libGL.so.1 mv -f /usr/lib/libGL.so.* /tmp apt-get install --reinstall libgl1-mesa-glx mv -f /tmp/libGL.so.* /usr/lib fi ;; wheezy*) rm -f /etc/alternatives/glx--libGL.so.1-x86_64-linux-gnu ln -sf /usr/lib/mesa-diverted/x86_64-linux-gnu/libGL.so.1 /etc/alternatives/glx--libGL.so.1-x86_64-linux-gnu rm -f /etc/alternatives/glx--linux-libglx.so ln -sf /usr/lib/xorg/modules/extensions/libglx.so /etc/alternatives/glx--linux-libglx.so ln -sf /usr/lib/xorg/modules/libfb.so /usr/lib/snail/libfb.so ln -sf /usr/lib/xorg/modules/libwfb.so /usr/lib/snail/libwfb.so ln -sf /usr/lib/x86_64-linux-gnu/nvidia/current/libGL.so.1 /usr/lib/snail/libGL.so.1 ln -sf /etc/alternatives/nvidia/libglx.so /usr/lib/snail/libglx.so ln -sf /usr/lib/nvidia/nvidia/nvidia_drv.so /usr/lib/snail/nvidia_drv.so ;; *) echo "No rules for Your distribution. Please make a bug report." exit -1 ;; esac ;; "Ubuntu") cp -f $SNAIL_INIT_D_PATH/snail-watcher.sysv /etc/init.d/snail-watcher cp -f $SNAIL_INIT_D_PATH/snail-xserver.sysv /etc/init.d/snail-xserver update-rc.d snail-xserver remove update-rc.d snail-watcher defaults /etc/init.d/snail-xserver stop /etc/init.d/snail-watcher start grep '^bbswitch$' /etc/modules || echo bbswitch >> /etc/modules grep '^acpi_call$' /etc/modules || echo acpi_call >> /etc/modules case "$DISTRIB_RELEASE" in 12.*) rm -f /etc/alternatives/x86_64-linux-gnu_gl_conf ln -sf /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf /etc/alternatives/x86_64-linux-gnu_gl_conf ldconfig rm -f /usr/lib/x86_64-linux-gnu/xorg/extra-modules ln -sf /usr/lib/nvidia-current/libGL.so.1 /usr/lib/snail/libGL.so.1 ln -sf /usr/lib/xorg/modules/libfb.so /usr/lib/snail/libfb.so ln -sf /usr/lib/nvidia-current/xorg/libglx.so /usr/lib/snail/libglx.so ln -sf /usr/lib/nvidia-current/libnvidia-glcore.so.[0-9][0-9]* /usr/lib/snail/ ln -sf /usr/lib/nvidia-current/tls/libnvidia-tls.so.[0-9][0-9]* /usr/lib/snail/ ln -sf /usr/lib/xorg/modules/libwfb.so /usr/lib/snail/libwfb.so ln -sf /usr/lib/nvidia-current/xorg/nvidia_drv.so /usr/lib/snail/nvidia_drv.so ;; *) echo "No rules for Your distribution. Please make a bug report." exit -1 ;; esac ;; "fedora") case "$DISTRIB_CODENAME" in Verne) echo bbswitch > /etc/modules-load.d/snail.conf echo acpi_call > /etc/modules-load.d/snail.conf cp -f $SNAIL_INIT_D_PATH/snail-watcher.systemd /etc/systemd/system/snail-watcher.service cp -f $SNAIL_INIT_D_PATH/snail-xserver.systemd /etc/systemd/system/snail-xserver.service systemctl --system daemon-reload systemctl start snail-watcher.service systemctl enable snail-watcher.service ln -sf /usr/lib64/xorg/modules/libfb.so /usr/lib/snail/libfb.so ln -sf /usr/lib64/xorg/modules/libwfb.so /usr/lib/snail/libwfb.so ln -sf /usr/lib64/xorg/modules/drivers/nvidia_drv.so /usr/lib/snail/nvidia_drv.so rm -f /usr/lib64/xorg/modules/extensions/nvidia/libglx.so rm -f /usr/lib64/nvidia/libGL.so.1 ln -sf /usr/lib64/nvidia/libGL.so.[0-9][0-9]* /usr/lib/snail/libGL.so.1 ln -sf /usr/lib64/xorg/modules/extensions/nvidia/libglx.so.[0-9][0-9]* /usr/lib/snail/libglx.so ;; *) echo "No rules for Your distribution. Please make a bug report." exit -1 ;; esac ;; *) echo "No rules for Your distribution. Please make a bug report." exit -1 ;; esac echo "Creating backups of original xorg.conf.* files and replacing with snail's versions..." if [[ ! -f /etc/X11/xorg.conf.nvidia.snail \ && ! -f /etc/X11/xorg.conf.intel.snail \ || "`grep 'Driver *\"intel\"' /etc/X11/xorg.conf`" == "" \ || "`grep 'BusID *"PCI:[0-9]:[0-9]:[0-9]' /etc/X11/xorg.conf{,.nvidia} | wc -l`" != 2 ]]; then [[ -f /etc/X11/xorg.conf && ! -f /etc/X11/xorg.conf.snail-bkp ]] && mv /etc/X11/xorg.conf /etc/X11/xorg.conf.snail-bkp [[ -f /etc/X11/xorg.conf.intel && ! -f /etc/X11/xorg.conf.intel.snail-bkp ]] && mv /etc/X11/xorg.conf.intel /etc/X11/xorg.conf.intel.snail-bkp [[ -f /etc/X11/xorg.conf.nvidia && ! -f /etc/X11/xorg.conf.nvidia.snail-bkp ]] && mv /etc/X11/xorg.conf.nvidia /etc/X11/xorg.conf.nvidia.snail-bkp cp -f /etc/X11/xorg.conf.intel.snail /etc/X11/xorg.conf.intel cp -f /etc/X11/xorg.conf.nvidia.snail /etc/X11/xorg.conf.nvidia ln -sf xorg.conf.intel /etc/X11/xorg.conf echo "Recognizing BusID of both chips and set it in xorg.conf.* files..." BusIDIntel="PCI:`lspci | grep VGA | grep Intel | cut -d" " -f1 | sed 's~\.~\:~g ; s~0\([0-9]\)~\1~g'`" BusIDNvidia="PCI:`lspci | grep VGA | grep -i nVidia | cut -d" " -f1 | sed 's~\.~\:~g ; s~0\([0-9]\)~\1~g'`" sed -i "s~BusIDIntel~$BusIDIntel~" /etc/X11/xorg.conf.intel sed -i "s~BusIDNvidia~$BusIDNvidia~" /etc/X11/xorg.conf.nvidia fi echo "`basename -- $0` is complete! ;-)"