[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

A minimalist backlight script from antiX (Was: Re: I need to be root to run this script)



Andrei POPESCU writes:

On Mi, 15 ian 20, 01:36:23, kaye n wrote:

[...]

> kaye@laptop:~$ backlight-brightness
> backlight-brightness: You need to be root to run this script
>
> Is it possible to be able to execute the script without being root?

Apparently the message is produced by the script itself, so no.

Seeing the script would confirm this. Linux distros put their code out
in the open, if you would mention which distro we might be able to find
it.

[...]

It appears as if the other distro configured their system to run stuff
as root, without password. Without more information we can only guess.

[...]

Hello fellow list members,

if you (like me) were curious about the script, I took some time and dug it
up. Apparently it is part of Linux distribution antiX since version 17,
attached for everyone's convenience in the version part of the antiX 19 live
DVD.

It decides by the writability of files under /sys/class/backlight whether it
is running with sufficient permissions, so setting up sudo will work if the
invocation of `backlight-brightness` is prefixed by sudo. In my tests
running it as root on a laptop it worked flawlessly under Debian, so this
script is certainly useful for us Debianers, too :) Actually, I wrote a
similar script for my local purposes which is basically a less-generic and
dialog-based version of the antiX variant with slightly different user
interface (and without the writability test :), attached as `ma_backlight`
if anyone cares.

Now how does antiX make this script run "as root"? Actually, it does not.
Instead, it changes the permissions on the backlight files s.t. they can be
written by regular users by means of an udev rule:
/etc/udev/rules.d/90-backlight.conf (also attached).

So dear OP, if you read my mail (seems the other one did not get so much
attention / never mind :) ) then the most clean solution for your situation
is to not fiddle with sudo at all but rather install the udev rule i.e. the
attached file to /etc/udev/rules.d and check if that might not already be
enough to resolve the issue (might need to trigger some
reloading/reprocessing of the udev rules after installing the file... I am
not so much an udev expert).

HTH
Linux-Fan

Attachment: backlight-brightness.gz
Description: application/gzip

#!/bin/sh -e
# Ma_Sys.ma backlight setting script 1.0.0, Copyright (c) 2019 Ma_Sys.ma.
# For further info send an e-mail to Ma_Sys.ma@web.de.

sel="$(dialog --menu "Select brightness" 17 40 14 \
	b200 "Normal bright" \
	b100 "Normal low" \
	b50  "Low" \
	b300 "Bright" \
	b500 "Bright" \
	b900 "Maximum" \
	b10  "Low" \
	b7   "Low" \
	b5   "Low" \
	b1   "Lowest with backlight" \
	b0   "Off" \
	cc   "Custom" 3>&1 1>&2 2>&3 3>&- || echo EXIT)"

case "$sel" in
(b*)
	echo "$(echo "$sel" | cut -c 2-)" > \
			/sys/class/backlight/intel_backlight/brightness;;
(cc)
	sel="$(dialog --inputbox "Enter brightness 0-900" 7 40 \
					3>&1 1>&2 2>&3 3>&- || echo EXIT)"
	if echo "$sel" | grep -qE '^[0-9]+$'; then
		echo $sel > /sys/class/backlight/intel_backlight/brightness
	elif [ "$sel" = EXIT ]; then
		exit 0
	else
		echo "Unknown input: $sel"
		exit 1
	fi;;
(EXIT)
	exit 0;;
(*)
	echo "Unknown selection: $sel"
	exit 1;;
esac
SUBSYSTEM=="backlight", ACTION=="add", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
SUBSYSTEM=="backlight", ACTION=="add", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"

Reply to: