You are not logged in.
Hi I realize the topic "permissions in Linux" is something that you can find very easily in the internet but I cant seem to figure out a solution for my problem.
I currently have a working script (taken from the ArchWiki) which enables me to change my display brightness. However I must be either superuser or root to be able to use it since it sends commands to the necessary devices.
I am currently using fluxbox as "desktop environment" and I want to be able as normal user to change the brightness without calling "sudo" everytime. I have also bound the necessary keys in the fluxbox/keys file to send the necessary commands to the script so my only problem is now with the permission.
Every help is much appreciated
Last edited by Triver (2011-12-13 17:34:41)
Offline
You say you do not want to type sudo, but I do think sudo is the best solution. if your script is in /usr/local/bin/brightness, the following entry in /etc/sudoers will allow anyone to run it without password.
ALL ALL= NOPASSWD: /usr/local/bin/brightness
then you write a wrapper script that call sudo:
#! /bin/sh
sudo /usr/local/bin/brightness "$@"
you can then use your wrapper script as a normal user.
If you realy do not want to use sudo (a valid reason would be security issue, it is always difficult with sudo to be 100% sure it can't be used for privilege escalation; although the configuration I have showed you is normally safe); you have to change the permission of the device file controling the brightness. In my system it is
/sys/devices/pci0000:00/0000:00:02.0/backlight/acpi_video0/brightness
and change its permission:
chmod a+w /sys/devices/pci0000:00/0000:00:02.0/backlight/acpi_video0/brightness
You can put the command in /etc/rc.local or better write an udev rule to put the correct permission (I can't help you much for this but read the manpage of udev and/or Google for "writing udev rules").
Offline
ok it works that way (at least when I execute the additional script which contains the sudo command).
for some reason fluxbox doesnt react when I press the keycode that I looked up with xev (although it works with a combination like "Mod4 b: exec ~/script")
anyway I think I'll stick with that solution and add some additional commands in the script (like toggle wlan on/off), thx for the quick help
edit: ok now I'm having difficulties with extending the script
I want to add additional paramters so the script can be used multifunctional depending on the parameter you launch it with.
however he seems to think that the String which I want to compare with the parameter is a command.
here's the code
#! /bin/sh
if [$1 = "brightness"]; then
if [$2 = "up"]; then
//call the actual brightness script with sudo
elif [$2 = "down"]; then
// call the actual brightness scrip with sudo
else
echo "invalid parameters!"
exit 1
fi
fi
exit 0
I execute the script like this
~/script brightness up
but he only returns me
~/script: line 2: [brightness: command not found
so whats wrong with the code?
Last edited by Triver (2011-12-13 16:03:07)
Offline
You need to add double quotes around $1 and $2. (Or a space between [ and $, but I believe it's good practice to use quotes, and it might even be mandatory to match the quotes around "brightness"... not sure.)
Offline
hmm I tried it now in every possible way with the quotes but its no help. everytime the same message "command not found"...
I tried every one of these
if ["$1" = "brightness"]; then
if ["$1" = brightness]; then
if [ $1 = "brightness"]; then //he says "missing ']' " here
if [""$1" = "brightness""]; then //he says "[brightness = brightness]: command not found"
if ['$1' = 'brightness']; then
if [\"$1\" = \"brightness\"]; then
but none of these are working...
Last edited by Triver (2011-12-13 16:25:35)
Offline
Add a space then .
if [ "$1" = "brightness" ]; then
Make that two spaces, in fact... (before ] too.)
Offline
that works
thx for the help
Offline
Great, don't forget to mark as solved!
Offline