Reply
Thread Tools
Estel's Avatar
Posts: 5,028 | Thanked: 8,613 times | Joined on Mar 2011
#1
Hello, and excuse me in advance, if this was covered before - ho ever, despite extensive searching, I wasn't able to find an answer. This explanation is going to be quite long, but I want to provide as much info as I can.

I develop some simple script (showing certain "glance" info derived from i2cget, based on shadowjk's bq27200 script), which put output to screen as maemo native notify. Basically, script contains 2 part - one for gathering and calculating info - based (mostly) on work by shadowjk - and second, forwarding output to screen.

For printing output, I use:

Code:
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"content-here-blablabla" uint32:0 string:""
The idea is that, after creating correct .desktop file pointing to script, shortcut can be placed on home desktop and/or it may be assigned to some hardware button (via third party applications, i.e. shortcutd). So, when needed, independently of device state (i.e. using fullscreen application), I can call my little script to provide info as notification.

Side note: I was using this method before to show notification info, derived from bq27x00 module (cat sys/class/power_supply/bq27200 etc.), and it worked like a charm - thanks to Nicolai, who helped me to understand calling upon notifications.

Gathering data from i2cget require root privileges - and here, the problem begin. For unknown reason, script works as it should when called from terminal, after "root" command (via rootsh package), but refuse to work when privileges were gained by "sudo gainroot". Furthermore, adding script as .sudoers result in same output, as when called after "sudo gainroot" - it prove that sudoers file is created properly (I think), but doesn't solve problem.

When called after "root", no errors, and notification info pop-out with correct data. When called after "sudo gainroot", or with "sudo" after .sudoers created, output in terminal is:

Code:
Failed to open connection to "session" message bus: (null)
I've checked what "root" script (that we get via rootsh, so we can use "root" in terminal to, well, gain root) contain - its "exec sudo gainroot --use-su". I've tried many combinations with --use-su together with "sudo gainroot" from terminal, to no avail (maybe I'm missing something here?).

What even more strange, bq27200.sh (script by shadowjk, that I used as base) works flawlessly with "sudo" after creating .sudoer for it. Also, using notification pop-up method (dbus-send etc), inside script that doesn't contain parts requiring root access (so, in my case, particularly parts from bq27200.sh, that works stand-alone) also result in no-problem. So, I got troubles only, when using script that contain *BOTH* gathering data requiring root, and displaying via aforementioned dbus-send method.

As result, I can't use this script from any kind of shortcut (desktop, hardware, whatever) - only from terminal, after "root". I've searched solid few days for possible solution - hence the "discovery" about it performing well with "root", but failing after "sudo gainroot" - but I'm still scratching my head clueless.

I'm attaching current version of script here (renamed to .sh.txt, to upload via forum mechanism), in case anyone want to try on her/his device (it may be little messy, it's developing version :P ). Any help/clues *really* much appreciated.
Attached Files
File Type: txt bnf.sh.txt (6.1 KB, 215 views)
__________________
N900's aluminum backcover / body replacement
-
N900's HDMI-Out
-
Camera cover MOD
-
Measure battery's real capacity on-device
-
TrueCrypt 7.1 | ereswap | bnf
-
Hardware's mods research is costly. To support my work, please consider donating. Thank You!

Last edited by Estel; 2011-09-11 at 16:00.
 

The Following 4 Users Say Thank You to Estel For This Useful Post:
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#2
Prefix dbus-send with run-standalone.sh

Code:
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"Voltage: $VOLT
 

The Following 6 Users Say Thank You to MohammadAG For This Useful Post:
Posts: 856 | Thanked: 1,681 times | Joined on Apr 2010 @ Aleppo ,Syria
#3
that is true you need

run-standalone.sh

before the script
cause when you type

root

it runs that script [standalone] with anything
also in user
but not with sudo gainroot

you can also :

Code:
 sudo run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications
but you need to do this first

Code:
echo "user ALL=(ALL) NOPASSWD: ALL" >> everybody.sudoers
echo "root ALL=(ALL) NOPASSWD: ALL" >> everybody.sudoers
mv everybody.sudoers /etc/sudoers.d
update-sudoers
this will let you run sudo #anything as root
also double root is possible
 

The Following 2 Users Say Thank You to karam For This Useful Post:
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#4
Originally Posted by karam View Post
that is true you need

run-standalone.sh

before the script
cause when you type

root

it runs that script [standalone] with anything
also in user
but not with sudo gainroot
No, neither user nor "root" use run-standalone.sh, it has to do with environment variables being set in one and not the other.

Originally Posted by karam View Post
you can also :

Code:
 sudo run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications
but you need to do this first

Code:
echo "user ALL=(ALL) NOPASSWD: ALL" >> everybody.sudoers
echo "root ALL=(ALL) NOPASSWD: ALL" >> everybody.sudoers
mv everybody.sudoers /etc/sudoers.d
update-sudoers
this will let you run sudo #anything as root
also double root is possible
That would also allow a sudo rm -rf /path/to/root, keeping some security on the system is saner.
 

The Following 3 Users Say Thank You to MohammadAG For This Useful Post:
Estel's Avatar
Posts: 5,028 | Thanked: 8,613 times | Joined on Mar 2011
#5
Thank You MohammadAG, obviously, it works like a charm now!

I must write this - it keeps me amazed how knowledgeable and competitive some people here are. Really, no sugar-coating - I could probably search for this +- forever without *any* success, and You MohammadAG "just" throw answer out of Your head.

---

Anyway, possibly last question on this topic - I like to learn when I've a chance - is there a way to run sh script with "sudo" via .desktop shortcut *without* terminal window flashing (turning on and closing after executing)?

I know, this one is probably simple newbie thing, but I've searched many threads about shortcut making on forum (not to mention wiki), and while .sh scripts that doesn't need root privileges run just fine without terminal, when invoked via "Exec=" in .desktop, the best thing I could achieve to run root things was to

Code:
Exec=/usr/bin/osso-xterm 'sudo bnf'
... which, obviously, flash terminal window, not to mention throwing us into dashboard (and outside any fullscreen program), if we're multitasking.

Every attempts with "bnf.sh | sudo gainroot", busybox sh -c 'usr/bin/bnf.sh | sudo gainroot' etc., failed miserably.

Thanks in advance for help, and really, enormous thanks for last one, I'm really impressed.


// Edit

Also thanks Karam, although I really would not like to open system for everything, just for this little script Nevertheless, thanks for trying to help.
__________________
N900's aluminum backcover / body replacement
-
N900's HDMI-Out
-
Camera cover MOD
-
Measure battery's real capacity on-device
-
TrueCrypt 7.1 | ereswap | bnf
-
Hardware's mods research is costly. To support my work, please consider donating. Thank You!

Last edited by Estel; 2011-08-25 at 00:18.
 

The Following User Says Thank You to Estel For This Useful Post:
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#6
What happens if you use Exec=sudo script.sh?
(You'll need an entry in sudoers.d, limit it to your script only of course).

If you're seeing a black window, that's the fake window hildon-desktop creates when an icon is clicked, so a real window replaces it later on, you can disable this by adding
Code:
X-App-Loading-Image=none
to the .desktop file
 

The Following 2 Users Say Thank You to MohammadAG For This Useful Post:
Estel's Avatar
Posts: 5,028 | Thanked: 8,613 times | Joined on Mar 2011
#7
Thanks for answer, ho ever, using Exec=sudo script.sh does nothing. Literally nothing, just nothing happens. That was the first thing I've tried after creating entry in sudoers.d I also got X-App-Loading-Image=none set.

When I execute "sudo script.sh" from terminal, it works as it should, so, probably, sudoers entry is ok.

// Edit

I've also tried to save terminal output from running desktop file, by:

Exec=sudo script.sh > /home/user/MyDocs/scriptlog.txt

(I've found it, while searching for solution - I don't know if it's right command)

...and scriptlog.txt was created, ho ever, contained nothing inside.
__________________
N900's aluminum backcover / body replacement
-
N900's HDMI-Out
-
Camera cover MOD
-
Measure battery's real capacity on-device
-
TrueCrypt 7.1 | ereswap | bnf
-
Hardware's mods research is costly. To support my work, please consider donating. Thank You!

Last edited by Estel; 2011-08-25 at 01:19.
 
Posts: 856 | Thanked: 1,681 times | Joined on Apr 2010 @ Aleppo ,Syria
#8
Originally Posted by MohammadAG View Post
No, neither user nor "root" use run-standalone.sh, it has to do with environment variables being set in one and not the other.

hmm would you please explain more Mohammad ? didn't really get it


Originally Posted by MohammadAG View Post
That would also allow a sudo rm -rf /path/to/root, keeping some security on the system is saner.


ok then i see but personally never faced security problem doing that
what might happen especially for a device like N900 ?

oh and you know something i'm really happy because i see an arabic person has a great knowledge about something might be really Sophisticated for a lot of people


i wish you would never visit syria
you will loose your mind because of the knowledge of it's people -_-

Last edited by karam; 2011-08-25 at 02:42.
 
Estel's Avatar
Posts: 5,028 | Thanked: 8,613 times | Joined on Mar 2011
#9
Originally Posted by karam View Post
hmm would you please explain more Mohammad ? didn't really get it
He mean, that "root" doesn't call upon run-standalone.sh. You can see personally, what it's doing - open /usr/bin/root in any text editor, i.e. leafpad or nano (or vi).
__________________
N900's aluminum backcover / body replacement
-
N900's HDMI-Out
-
Camera cover MOD
-
Measure battery's real capacity on-device
-
TrueCrypt 7.1 | ereswap | bnf
-
Hardware's mods research is costly. To support my work, please consider donating. Thank You!
 

The Following User Says Thank You to Estel For This Useful Post:
Estel's Avatar
Posts: 5,028 | Thanked: 8,613 times | Joined on Mar 2011
#10
Sorry for bumping, but maybe anyone have idea about it?:

Originally Posted by Estel View Post
Thanks for answer, ho ever, using Exec=sudo script.sh does nothing. Literally nothing, just nothing happens. That was the first thing I've tried after creating entry in sudoers.d I also got X-App-Loading-Image=none set.

When I execute "sudo script.sh" from terminal, it works as it should, so, probably, sudoers entry is ok.

// Edit

I've also tried to save terminal output from running desktop file, by:

Exec=sudo script.sh > /home/user/MyDocs/scriptlog.txt

(I've found it, while searching for solution - I don't know if it's right command)

...and scriptlog.txt was created, ho ever, contained nothing inside.
I just can't believe that it's not possible to set shortcut - via .desktop file - to some command that require root. Recently, I've also tried Queen BeeCon widget with command
Code:
sudo bnf.sh
, which exact same results - nothing (literally, nothing) happen when I execute it. Again, typing this manually in terminal works flawlessly.

For reference, I'm attaching actual version of script, + (more important for current problem, I think) .desktop file. Could anyone knowledgeable check it inside device? Maybe it's just "my" problem, not code problem?

Note:
Currently, there is:
Code:
Exec=sudo bnf.sh
...but I've tried also with
Code:
Exec='sudo bnf.sh'
Exec="sudo bnf.sh"
Exec=sudo 'bnf.sh'
Exec=sudo "bnf.sh"
...and every possible combination of these.

I can get it to (semi) work by:
Code:
Exec=osso-xterm -e "sudo bnf.sh"
... but that "flash" screen with terminal window poping up first, + is much slower to execute.

// Edit

Using ShortcutD, I can set:
Code:
sudo bnf.sh
...as custom command + set it for hardware button (i.e to execute, when I half-press camera button), but still no joy to make it working as desktop shortcut.

I got plans for some (maybe) useful and more complicated scripts, that would be handy with desktop shortcuts for them, but every single one require root. I have no idea why the heck it doesn't want to work with:
Exec=sudo <name>.sh

(Actual version is here:
http://talk.maemo.org/showpost.php?p...3&postcount=17)
__________________
N900's aluminum backcover / body replacement
-
N900's HDMI-Out
-
Camera cover MOD
-
Measure battery's real capacity on-device
-
TrueCrypt 7.1 | ereswap | bnf
-
Hardware's mods research is costly. To support my work, please consider donating. Thank You!

Last edited by Estel; 2011-09-11 at 19:51.
 

The Following User Says Thank You to Estel For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 02:05.