You are not logged in.

#1 2017-09-08 21:02:25

nicolo
Banned
Registered: 2013-08-10
Posts: 90

[SOLVED] script to set screen brightness that does not require root

To change screen brightness in dwm, I use

sudo brightness up

where brightness is the script

#!/bin/bash
if [ "$EUID" -ne 0 ]
then
	echo "Please run $0 as root"
	exit
fi

bd=/sys/devices/pci0000:00/0000:00:02.0/drm/card*/card*-eDP-1/intel_backlight/brightness

bdv=$(cat $bd)

case $1 in
	up)
		echo $(( bdv + 100 )) > $bd
		cat $bd
	;;
	down)
		echo $(( bdv - 100 )) > $bd
		cat $bd
	;;
	*)
	echo "$bdv"
esac

The drawback is that if I bind that to a keyboard key in dwm as in

static const char *cmdbrightnessup[]  = { "sudo", "brightness", "up", NULL };
static Key keys[] = {
	/* modifier                     key        function        argument */
	{ 0,                            XF86MonBrightnessUp,       spawn,         {.v = cmdbrightnessup } }
};

then my user needs to have root access without being prompt for a password for it to work.

Is there another way to set screen brightness that does not require root access? after all, in gnome the same button is bound to the same actoin, and there root access is not needed.

Last edited by nicolo (2017-09-09 02:32:18)

Offline

#2 2017-09-08 21:08:45

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] script to set screen brightness that does not require root

Add an entry to sudoers so that your user can run the brightness command as root without needing a password.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2017-09-08 21:09:16

nicolo
Banned
Registered: 2013-08-10
Posts: 90

Re: [SOLVED] script to set screen brightness that does not require root

Actually, I've just realised that it boils down to add that command to sudoers file. So my question: how do I add a command to sudoers such that every user can run it without being asked for root password? and perhaps, since it is related, how do I add pacman command so that only my user is not prompted by root pwd?

Offline

#4 2017-09-08 21:18:27

ayekat
Member
Registered: 2011-01-17
Posts: 1,632

Re: [SOLVED] script to set screen brightness that does not require root

nicolo wrote:

how do I add a command to sudoers such that every user can run it without being asked for root password?

Did you know we have a Wiki for that kind of things? Or web search engines?

Also, I know there is xbacklight, although I don't know if that's suitable here...
Have you tried making the backlight buttons work with ACPI? It's probably less of a hack (and would also work in a TTY environment).


pkgshackscfgblag

Offline

#5 2017-09-09 02:31:32

nicolo
Banned
Registered: 2013-08-10
Posts: 90

Re: [SOLVED] script to set screen brightness that does not require root

I think that adding to /etc/sudoers

ALL ALL=NOPASSWD: /path/to/brightness
myuser ALL=NOPASSWD: /usr/bin/pacman -Syyu

should do the job. Thanks.

Last edited by nicolo (2017-09-09 02:31:59)

Offline

#6 2017-09-09 06:37:00

ayekat
Member
Registered: 2011-01-17
Posts: 1,632

Re: [SOLVED] script to set screen brightness that does not require root

nicolo wrote:
myuser ALL=NOPASSWD: /usr/bin/pacman -Syyu

May I ask what the purpose of this is?

Also, please read the pacman man page (especially the section about -y), because regularly running -Syyu is not only pointless, it also generates unnecessary traffic, as you download a new version of the package database everytime regardless of whether it is necessary or not.

Last edited by ayekat (2017-09-09 06:43:16)


pkgshackscfgblag

Offline

#7 2017-09-09 11:24:59

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [SOLVED] script to set screen brightness that does not require root

ayekat wrote:

May I ask what the purpose of this is?

My guess is that nicolo has another script running automatic updates in the background.  In which case we'll see him back here soon when that totally borks his system.  I'll make the popcorn.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2017-09-09 12:08:05

RoundCube
Member
Registered: 2016-05-14
Posts: 42

Re: [SOLVED] script to set screen brightness that does not require root

nicolo wrote:
myuser ALL=NOPASSWD: /usr/bin/pacman -Syyu

It would be useful for manual updating too.

Last edited by RoundCube (2017-09-09 12:11:53)

Offline

#9 2017-09-09 15:51:11

nicolo
Banned
Registered: 2013-08-10
Posts: 90

Re: [SOLVED] script to set screen brightness that does not require root

Well your guess is bullshit. It's just so that I don't have to type a password when I upate with pacman, which I do by hand daily. I see, so is it better to have -Syu?

Last edited by nicolo (2017-09-09 15:51:43)

Offline

Board footer

Powered by FluxBB