-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgpu-select
executable file
·94 lines (89 loc) · 2.84 KB
/
gpu-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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
#
# NAME
#
# gpu-select - a script to switch between Intel/NVIDIA graphics
#
# SYNOPSIS
#
# gpu-select intel|hybrid|nvidia|query
#
# DESCRIPTION
#
# gpu-select is a utility similar to Ubuntu's prime-select(1) that
# allows one to switch between Intel/NVIDIA graphics on PRIME systems.
#
# OPTIONS
#
# intel turn off the GPU and run X on Intel graphics
# hybrid turn on the GPU but run X on Intel graphics
# nvidia turn on the GPU and run X on NVIDIA graphics
# query report state (i.e., contents of /etc/gpu-select/state)
#
service() {
if systemctl list-unit-files | grep -q "$2"
then
systemctl "$1" "$2"
fi
}
case "$1" in
query)
if [ -f /etc/gpu-select/state ]
then
cat /etc/gpu-select/state
exit 0
else
echo >&2 "${0##*/}: unknown; have you run gpu-select before?"
exit 1
fi
;;
intel|hybrid|nvidia)
# From now on, bail out on the first error and always run as root.
set -eu
test $(id -u) -eq 0 || exec sudo -- "$0" "$@"
;;
*)
echo >&2 "usage: ${0##*/} intel|hybrid|nvidia|query"
exit 1
;;
esac
# X configuration files will be copied here depending on the supplied option.
mkdir -p "/etc/X11/xorg.conf.d"
x11conf="/etc/X11/xorg.conf.d/gpu-select.conf"
# X configuration files for NVIDIA and Intel.
nvidia="/etc/gpu-select/nvidia.conf"
intel="/etc/gpu-select/intel.conf"
case "$1" in
intel)
echo >&2 "${0##*/}: disabling NVIDIA drivers."
service stop nvidia-persistenced.service
modprobe -r nvidia-drm
modprobe -r nvidia-modeset
modprobe -r nvidia-current
modprobe -r nvidia
echo >&2 "${0##*/}: turning off the NVIDIA GPU."
echo "OFF" >/proc/acpi/bbswitch
echo >&2 "${0##*/}: copying X configuration files for Intel."
cp -f "$intel" "$x11conf"
echo "intel" >/etc/gpu-select/state
;;
hybrid|nvidia)
echo >&2 "${0##*/}: turning on the NVIDIA GPU."
echo "ON" >/proc/acpi/bbswitch
echo >&2 "${0##*/}: loading NVIDIA drivers."
modprobe nvidia-drm modeset=1
modprobe nvidia-modeset
modprobe nvidia
service start nvidia-persistenced.service
case "$1" in
hybrid) echo >&2 "${0##*/}: copying X configuration files for Intel."
cp -f "$intel" "$x11conf"
echo "hybrid" >/etc/gpu-select/state
;;
nvidia) echo >&2 "${0##*/}: copying X configuration files for NVIDIA."
cp -f "$nvidia" "$x11conf"
echo "nvidia" >/etc/gpu-select/state
;;
esac
;;
esac