#!/bin/bash echo "Test for acpi_call/vgaswitcheroo" if [ -f /sys/kernel/debug/vgaswitcheroo/switch ]; then echo "vgaswitcheroo is OK! ;-)" else if [ -f /proc/acpi/call ]; then echo "acpi_call is OK! ;-)" else modprobe acpi_call if [ -f /proc/acpi/call ]; then echo "Warning: Please configure acpi_call module for autoloading on system startup!" else echo "No vgaswitcheroo/acpi_call found. Please configure/install one of them! ;-(" exit -1 fi fi 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/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%%\)*} 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" [[ -d /usr/lib64/snail && ! -d /usr/lib/snail ]] && ln -s /usr/lib64/snail /usr/lib/snail 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 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/extensions /usr/lib/snail/ ln -sf /usr/lib/opengl/nvidia/lib /usr/lib/snail/ ln -sf /usr/lib/xorg/modules /usr/lib/snail/ grep acpi_call /etc/conf.d/modules || echo 'modules="${modules} acpi_call' >> /etc/conf.d/modules ;; "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 '^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 ;; "fedora") case "$DISTRIB_CODENAME" in Verne) 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..." [[ -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 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 echo "`basename -- $0` is complete! ;-)"