-
Notifications
You must be signed in to change notification settings - Fork 4
/
switcher
executable file
·109 lines (78 loc) · 2.49 KB
/
switcher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/sh
# NVIDIA_DRIVER_VER scans dpkg to guess the version, below is static value if you prefer
export MY_USER=maquis196
export NVIDIA_DRIVER_VER=`dpkg -l | grep binary\ driver | gawk '{print $2}'`
#export NVIDIA_DRIVER_VER=nvidia-331-updates
export NVIDIA_MOD_NAME=`echo $NVIDIA_DRIVER_VER | sed s/-/_/g`
#export GUI=`echo $XDG_CURRENT_DESKTOP`
#export GUI='XFCE4'
if [ -z $NVIDIA_DRIVER_VER ]; then
echo "NVIDIA_DRIVER_VER is unset, please check binary drivers are installed or set manually"
exit 1
else
echo "setting driver version to $NVIDIA_DRIVER_VER"
fi
if [ -z $GUI ]; then
echo "GUI is unset, please manually set"
exit 1
else
echo "setting gui to $GUI"
fi
if [ $# = 0 ]; then
echo
echo "Use the one of following commands:"
echo
echo "1) Switch to nvidia prime"
echo "2) Switch to intel graphics"
echo
read command
if [ "$command" = "1" ]; then
sudo -E nohup "$0" nvidia
fi
if [ "$command" = "2" ]; then
sudo -E nohup "$0" intel
fi
exit
fi
if [ `whoami` != "root" ]; then
echo "You must run it as root";
exit
fi
if [ "$1" = "nvidia" ]; then
service lightdm stop
echo "ON" > /proc/acpi/bbswitch
sleep 2
modprobe $NVIDIA_DRIVER_VER
cp /etc/X11/xorg.conf-nvidia /etc/X11/xorg.conf
echo 'xrandr --setprovideroutputsource modesetting NVIDIA-0 && xrandr --auto' > /home/$MY_USER/.xsessionrc
echo "start on runlevel [2345]' > /etc/init/nvidia-moja.conf
echo " script' >> /etc/init/nvidia-moja.conf
echo " echo "ON" > /proc/acpi/bbswitch' >> /etc/init/nvidia-moja.conf
echo " modprobe $NVIDIA_DRIVER_MOD" >> /etc/init/nvidia-moja.conf
echo "end script" >> /etc/init/nvidia-moja.conf
update-alternatives --set x86_64-linux-gnu_gl_conf /usr/lib/$NVIDIA_DRIVER_VER/ld.so.conf
update-alternatives --set i386-linux-gnu_gl_conf /usr/lib/$NVIDIA_DRIVER_VER/alt_ld.so.conf
ldconfig
service lightdm restart
fi
if [ "$1" = "intel" ]; then
service lightdm stop
if [ -e /etc/X11/xorg.conf ]; then
rm /etc/X11/xorg.conf
else
echo "xorg.conf not present. Skipping"
fi
echo > /home/$MY_USER/.xsessionrc
if [ -e /etc/init/nvidia-moja.conf ]; then
rm /etc/init/nvidia-moja.conf
else
echo "nvidia-moja.conf not present. Skipping"
fi
update-alternatives --set x86_64-linux-gnu_gl_conf /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf
update-alternatives --set i386-linux-gnu_gl_conf /usr/lib/i386-linux-gnu/mesa/ld.so.conf
echo "OFF" > /proc/acpi/bbswitch
sleep 2
rmmod $NVIDIA_DRIVER_MOD
ldconfig
service lightdm restart
fi