forked from Witko/nvidia-xrun
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nvidia-xrun
90 lines (79 loc) · 2.1 KB
/
nvidia-xrun
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
#!/bin/bash
DRY_RUN=0
function printHelp {
echo "Utility to run games and applications in separate X on discrete Nvidia graphic card"
echo "Usage: "
echo "nvidia-xrun [<options>] <app>"
echo "Options: "
echo " -d Dry run - prints the final command but does not execute it"
}
function execute {
if [ $DRY_RUN -eq 1 ]
then
echo ">>Dry run. Command: $*"
else
eval $*
fi
}
if [[ $EUID -eq 0 ]]; then
echo "This script must not be run as root" >&2
exit 1
fi
if [ "$1" == "-d" ]
then
DRY_RUN=1
shift 1
fi
if [ $# -eq 0 ]
then
printHelp
exit 1
fi
# calculate current VT
LVT=`sudo fgconsole`
# calculate first usable display
XNUM="-1"
SOCK="something"
while [ ! -z "$SOCK" ]
do
XNUM=$(( $XNUM + 1 ))
SOCK=$(ls -A -1 /tmp/.X11-unix | grep "X$XNUM" )
done
NEWDISP=":$XNUM"
if [ ! -z "$*" ] # generate exec line if arguments are given
then
# test if executable exists
if [ ! -x "$(which $1 2> /dev/null)" ]
then
echo "$1: No such executable!"
exit 1
fi
# generate exec line
EXECL="$(which $1)"
shift 1
EXECL="$EXECL $*"
EXECPH=""
else # prepare to start new X sessions if no arguments passed
EXECL=""
EXECPH="New X session"
fi
EXECL="/etc/X11/xinit/nvidia-xinitrc $EXECL"
COMMAND="startx $EXECL -- $NEWDISP vt$LVT -background none -noreset -keeptty -verbose 7 -config nvidia-xorg.conf"
echo "Configuring Xorg to use root as nvidia doesn't have kms"
execute "sudo sed -i s/=no/=yes/g /etc/X11/Xwrapper.config"
echo 'Setting glx for nvidia'
execute "sudo update-alternatives --set glx /usr/lib/nvidia"
echo 'Waking up nvidia GPU'
execute "sudo tee /proc/acpi/bbswitch <<<ON"
echo 'Loading nvidia module'
execute "sudo modprobe nvidia"
execute "sudo modprobe nvidia_drm"
execute $COMMAND
echo 'Unloading nvidia module'
execute "sudo rmmod nvidia_drm nvidia_modeset nvidia"
echo 'Turning off nvidia GPU'
execute "sudo tee /proc/acpi/bbswitch <<<OFF"
echo 'Setting glx for intel/bumblebee'
execute "sudo update-alternatives --set glx /usr/lib/nvidia/bumblebee"
echo "Resetting Xorg for non-root login"
execute "sudo sed -i s/=yes/=no/g /etc/X11/Xwrapper.config"