This repository has been archived by the owner on May 22, 2019. It is now read-only.
forked from konstantingoretzki/AntergosPrime
-
Notifications
You must be signed in to change notification settings - Fork 4
/
prime-select
73 lines (68 loc) · 2.35 KB
/
prime-select
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
#!/bin/bash
function GetAlternative() {
if [ "$(ls /var/lib/pacman/local/mesa-libgl* 2> /dev/null)" ]; then
echo "intel"
elif [ "$(ls /var/lib/pacman/local/nvidia-libgl* 2> /dev/null)" ]; then
echo "nvidia"
fi
}
# Install the desired LibGL
function SetAlternative() {
desired=$1
currentalternative=$(GetAlternative)
if [ "$desired" = "$currentalternative" ]; then
echo "LibGL already is $currentalternative, nothing to do"
else
if [ "$desired" = "nvidia" ]; then
#pacman --noconfirm -Rdd mesa lib32-mesa xf86-video-intel
pacman --noconfirm -S nvidia-utils lib32-nvidia-utils xf86-video-intel
elif [ "$desired" = "intel" ]; then
pacman --noconfirm -Rdd nvidia-utils lib32-nvidia-utils
pacman --noconfirm -S mesa lib32-mesa
pacman --noconfirm -S xf86-video-intel
fi
fi
}
# Write discrete card desired state in a file to be used later by another script
function WriteDesiredConfig() {
discretestate=$1
file="/etc/prime/state"
if [ "$discretestate" = "nvidia" ]; then
echo "ON" > "$file"
cp /etc/prime/xorg.conf /etc/X11/
if [ -f /etc/X11/xorg.conf.d/20-intel.conf ]; then
rm /etc/X11/xorg.conf.d/20-intel.conf
fi
cp /etc/prime/Xsetup /usr/share/sddm/scripts/
chmod +x /usr/share/sddm/scripts/Xsetup
if ! lsmod | grep "bbswitch" &> /dev/null ; then
modprobe bbswitch
fi
echo "ON" >> /proc/acpi/bbswitch
elif [ "$discretestate" = "intel" ]; then
echo "OFF" > "$file"
cp /etc/prime/20-intel.conf /etc/X11/xorg.conf.d/
if [ -f /etc/X11/xorg.conf ]; then
rm /etc/X11/xorg.conf
fi
cp /etc/prime/Xsetup_intel /usr/share/sddm/scripts/Xsetup
chmod +x /usr/share/sddm/scripts/Xsetup
fi
}
argument=$1
# Checks if argument is valid and if not already active will attempt to do so.
if [ "$argument" = "intel" ] || [ "$argument" = "nvidia" ]; then
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
SetAlternative "$argument"
WriteDesiredConfig "$argument"
else
if [ "$argument" = "query" ]; then
currentalternative=$(GetAlternative)
echo "$currentalternative"
else
echo "Usage prime.sh intel|nvidia|query"
fi
fi