brightness - set brightness in TTY

Submitted scripts and programs
Forum rules
Your own work only.
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

brightness - set brightness in TTY

Unread post by machinebacon » Sat Jan 16, 2016 7:17 pm

Yeah it is actually an easy thing if you know how. No, xbacklight no workee in TTY.

Recent kernels have a bug with saying

Code: Select all

 [drm:intel_enable_lvds [i915]] *ERROR* timed out waiting for panel to power on
in dmesg. The "acpi_osi=Linux acpi_backlight=vendor" fix does not help, and it happens across different distros.

It may or may not work if your backlight classes are acpi and vendor.

1) Put this script into /usr/sbin/brightness
2) make it executable with "chmod +x /usr/sbin/brightness"
3) add the command "/usr/sbin/brightness 8" to /etc/rc.local (before the exit line) and you will have a highly illuminated screen at login.

values between 1 and 8 are accepted, 8 being the brightest

Code: Select all

#!/bin/bash
[[ -z $1 ]] && echo "Usage: $0 [1...8] " && exit 0
[[ "$1" -lt "1" ]] || [[ "$1" -gt "8" ]] && echo "Value out of range" && exit 0

# find the backlight names
BL_NAME=(`ls /sys/class/backlight/`)

# path to brightness setting in sys
SYS_PATH="/sys/class/backlight/$BL_NAME/brightness"

# set brightness value to $1
VAL=$1

printf "detected backlight drivers..... $BL_NAME \n"
echo $VAL > $SYS_PATH
printf "set brightness to $VAL in $SYS_PATH \n"
Of course this works nicely as keybinding -- provided you add the script as entry to sudoers, because it needs elevated privileges.
..gnutella..

User avatar
elixir
Weight Watcher
Posts: 357
Joined: Fri Feb 21, 2014 8:25 am

Re: brightness - set brightness in TTY

Unread post by elixir » Sun Mar 06, 2016 8:29 am

Light is also a good alternative to this. It may not be as simple as this script, but it does not require you to have root permissions to change your brightness. The only dependencies it has is "help2man".

EDIT: You do indeed need to change the owner of the program to "root" and add executable permissions, but you are allowed to adjust brightness without the use of elevated permissions.
Out of the corner of your eye you spot him... Shia LaBeouf.

https://www.youtube.com/watch?v=o0u4M6vppCI

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: brightness - set brightness in TTY

Unread post by machinebacon » Sun Mar 06, 2016 3:53 pm

^ anything that talks with the /sys folder needs elevated privileges, no matter what wrapper we put around it. If you make the owner 'root', or you add a script to sudoers, or you run it as root - all are elevated permissions.

Of course one could use *kit, but thats anyway not the point.

OP is about fixing the kernel bug that happens with certain gfx cards (that reset /sys/class/backlight to an unusable value) by simply putting an accepted value in place. It is not meant to do anything else. And because OP is /usually/ run at boot time, the elevated rights are given anyway. If people want to have keybindings, neither this script nor that one will change the brightness value without tinkering with rights management.
..gnutella..

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: brightness - set brightness in TTY

Unread post by pidsley » Sun Mar 06, 2016 3:55 pm

I don't have a laptop to test this on, but couldn't you just chown the brightness file to allow user access? It seems silly to use an 874-line C program to do something that can be done by an eight-line bash script, even if the bash script requires root access.

(edit) or add the script to sudoers -- either way I don't see why root access is a problem here.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: brightness - set brightness in TTY

Unread post by machinebacon » Sun Mar 06, 2016 4:01 pm

^ you typed while I edited my previous reply. So; yes.
..gnutella..

Post Reply