You are not logged in.

#1 2011-12-13 13:58:39

Triver
Member
Registered: 2009-03-29
Posts: 71

[Solved] Problems with permissions for a script

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 wink

Last edited by Triver (2011-12-13 17:34:41)

Offline

#2 2011-12-13 14:33:21

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: [Solved] Problems with permissions for a script

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

#3 2011-12-13 15:17:41

Triver
Member
Registered: 2009-03-29
Posts: 71

Re: [Solved] Problems with permissions for a script

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 wink

edit: ok now I'm having difficulties with extending the script tongue
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

#4 2011-12-13 16:07:46

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: [Solved] Problems with permissions for a script

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

#5 2011-12-13 16:25:18

Triver
Member
Registered: 2009-03-29
Posts: 71

Re: [Solved] Problems with permissions for a script

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

#6 2011-12-13 16:36:41

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: [Solved] Problems with permissions for a script

Add a space then smile.

if [ "$1" = "brightness" ]; then

Make that two spaces, in fact... (before ] too.)

Offline

#7 2011-12-13 16:42:11

Triver
Member
Registered: 2009-03-29
Posts: 71

Re: [Solved] Problems with permissions for a script

that works big_smile

thx for the help

Offline

#8 2011-12-13 17:08:38

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: [Solved] Problems with permissions for a script

Great, don't forget to mark as solved!

Offline

Board footer

Powered by FluxBB