Reply
Thread Tools
Posts: 30 | Thanked: 4 times | Joined on Dec 2009
#11
i tried to do as you said qwerty but i can't get it working, i'm not sure what to try now, i think texas has summed it up nicely, i'll have to run it from root for now.

Is there a way to clear the contents of the powerlevel.sh file from x terminal? i accidentially but the command in the file once wrong.
 
jaeezzy's Avatar
Posts: 664 | Thanked: 160 times | Joined on Jul 2008 @ Australia
#12
Originally Posted by LozBlake View Post
I think i have this problem, i have write the script as written above amd made the change zoi said, it works fine when i run it when i'm already root in xterm however it doesn't change the powerlevel if i run it as user, even though the sudo root command is in there, all it does is give me root access.

Any ideas what i need to change?
Open up any terminal you are comfortable with and type the following:

Code:
#!/bin/sh
if [ `id -u` != 0 ]; then
sudo gainroot <<EOF
$0 $*
EOF
exit
fi
echo 118 > /sys/class/i2c-adapter/i2c-2/2-0063/power_level
It changes to root if you are just user and executes the command or else just executes the command.
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#13
Originally Posted by LozBlake View Post
i tried to do as you said qwerty but i can't get it working, i'm not sure what to try now, i think texas has summed it up nicely, i'll have to run it from root for now.

Is there a way to clear the contents of the powerlevel.sh file from x terminal? i accidentially but the command in the file once wrong.
Odd...

Well, this worked for me:
Code:
#! /bin/sh

VAL=118
FILE=/sys/class/i2c-adapter/i2c-2/2-0063/power_level

if [ $(id -u) = 0 ]; then
	echo $VAL > $FILE
else
	echo "echo $VAL > $FILE" | sudo gainroot
fi

cat $FILE
 
Posts: 152 | Thanked: 41 times | Joined on Dec 2009 @ Sydney
#14
Originally Posted by texaslabrat View Post
You can't use sudo like that...the "sudo gainroot" launches a new shell process but the next command in your script executes in the exiting "user"-owned shell. It's not a hard problem to fix in a "normal" linux distro (I typically use "su" with flags to switch users inside a script) but I'm not sure how you would do it with the seemingly unique way that the root account and user account are related in maemo. On the surface it would seem as though you could simply issue a "sudo ./myscript" but I don't think that works out of the box in maemo. Hopefully some of the more seasoned maemo veterans will have an answer for the on-liner you are seeking to create.

One thing you *might* try is to setuid the script (chown file to root, and then chmod u+s the file) that does the things you want to do. You would then execute it as "user" but it would automagically run as root. Can provide a nice huge security hole in most unix systems, but with the "sudo gainroot" thing that doesn't even require a password, I'm not sure that's a concern in this particular case.
Just run visudo as root and add scripts/commands you want to be able to run as a normal user with with root privileges.

That's the idea of the sudo system.
 
Posts: 247 | Thanked: 37 times | Joined on Aug 2009 @ Los Angeles
#15
Originally Posted by DaveQB View Post
Just run visudo as root and add scripts/commands you want to be able to run as a normal user with with root privileges.

That's the idea of the sudo system.
Is there a webpage describing the "sudo system"? Years ago I got some AIX experience, but I've forgotten a lot over the years....
 
Posts: 271 | Thanked: 220 times | Joined on Sep 2009
#16
Originally Posted by DaveQB View Post
Just run visudo as root and add scripts/commands you want to be able to run as a normal user with with root privileges.

That's the idea of the sudo system.
That's not how it's done in maemo as far as I can tell. Take a look at /etc/sudoers.d. But you have the right idea, though for the OP's issue I still think just setuid'ing the file is the cleanest/most straightforward way to do it, but that's just my opinion.
 
Posts: 30 | Thanked: 4 times | Joined on Dec 2009
#17
Originally Posted by jaeezzy View Post
Open up any terminal you are comfortable with and type the following:

Code:
#!/bin/sh
if [ `id -u` != 0 ]; then
sudo gainroot <<EOF
$0 $*
EOF
exit
fi
echo 118 > /sys/class/i2c-adapter/i2c-2/2-0063/power_level
It changes to root if you are just user and executes the command or else just executes the command.
will this put the command into the powerlevel.sh file so in future i will just need to run ./powerlevel.sh or will i need to do more for that to happen? also do i type that in as one string or do i press enter after every line? sorry if this is all a bit dumb but i'm a complete novice with linux
 
Posts: 156 | Thanked: 90 times | Joined on Jan 2010
#18
You can use rootsh instead of sudo. For example: rootsh <command> will execute <command> as root.
 

The Following User Says Thank You to rooted For This Useful Post:
jaeezzy's Avatar
Posts: 664 | Thanked: 160 times | Joined on Jul 2008 @ Australia
#19
Originally Posted by LozBlake View Post
will this put the command into the powerlevel.sh file so in future i will just need to run ./powerlevel.sh or will i need to do more for that to happen? also do i type that in as one string or do i press enter after every line? sorry if this is all a bit dumb but i'm a complete novice with linux
Sorry, here's what you do:

1. Open up xterm.
2. In xterm type: vi powerlevel.sh
3. Press "i" key it will activate "Insert" mode.
4. Type as it is there (every line is a new line so there is enter after every line however, you don't press space in the front).
5. After you have finished typing everything, press the esc key and then ":" followed by "wq" (without double quotes) and hit enter.
6. It will save your file as powerlevel.sh in the same directory you are currently working.
7. Again in the xterm type: chmod +x powerlevel.sh
8. To execute: ./powerlevel.sh

That's it.
 

The Following User Says Thank You to jaeezzy For This Useful Post:
Posts: 152 | Thanked: 41 times | Joined on Dec 2009 @ Sydney
#20
Originally Posted by RWFarley View Post
Is there a webpage describing the "sudo system"? Years ago I got some AIX experience, but I've forgotten a lot over the years....
Here's a start:
https://help.ubuntu.com/community/RootSudo

A little verbose, but you can skim read to the parts relevant to you [and Maemo]
 
Reply


 
Forum Jump


All times are GMT. The time now is 12:59.