diff --git a/README.md b/README.md index fe4330b..19a622e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,16 @@ It started with a revelation that bumblebee in current state offers very poor pe 1. run `nvidia-xrun [app]` 1. enjoy -Currently sudo is required as the script needs to wake up GPU, modprobe the nvidia driver and perform cleanup afterwards. For this we use bbswitch. +### Passwordless `sudo` +Whitelisting `nvidia-toggle` in your sudoer's file allows you to use `nvidia-xrun` without entering your password: + +``` +%users ALL=(root) NOPASSWD:/usr/bin/nvidia-toggle +``` + +...where `/usr/bin/nvidia-toggle` is the full path to the `nvidia-toggle` script. + +Note: it is a good practice to ensure binaries/scripts/etc. that are whitelisted for passwordless `sudo` are owned by root. ## Structure * **nvidia-xrun** - uses following dir structure: diff --git a/nvidia-toggle b/nvidia-toggle new file mode 100755 index 0000000..b9f2795 --- /dev/null +++ b/nvidia-toggle @@ -0,0 +1,82 @@ +#!/bin/bash +# nvidia-toggle [-d] (on | off) + +DRY_RUN=0 +if [[ $EUID -ne 0 ]]; then + (>&2 echo "This script must be run as root") + exit 1 +fi + +function execute { + if [ ${DRY_RUN} -eq 1 ] + then + echo ">>Dry run. Command: $*" + else + eval $* + fi +} + +function die { + (>&2 echo $@) + exit 1 +} + +if [ "$1" == "-d" ] + then + DRY_RUN=1 + shift 1 +fi + +case $1 in +on) + # --------- TURNING ON GPU ----------- + echo 'Waking up nvidia GPU' + if ! [ -f /proc/acpi/bbswitch ] + then + execute "modprobe bbswitch" || die "Can't modprobe bbswitch" + fi + execute "tee /proc/acpi/bbswitch <<&2 echo $@) + exit 1 +} if [[ $EUID -eq 0 ]]; then echo "This script must not be run as root" >&2 @@ -69,51 +73,13 @@ EXECL="/etc/X11/xinit/nvidia-xinitrc $EXECL" COMMAND="xinit $EXECL -- $NEWDISP vt$LVT -nolisten tcp -br -config nvidia-xorg.conf -configdir nvidia-xorg.conf.d" -# --------- TURNING ON GPU ----------- -echo 'Waking up nvidia GPU' -if ! [ -f /proc/acpi/bbswitch ] -then - execute "sudo modprobe bbswitch" -fi -execute "sudo tee /proc/acpi/bbswitch <<