How to use situations app as toggle airplane mode

update: i did rephrase question to fit to my goal: to toggle airplane mode using situations and here is the way i did implement it:

first i tried to run situations as root:

when i do devel-su
then password
then harbour-situations2application

i get the errorXDG_RUNTIME_DIR not set in the environment

and app wont start

later i tried to use scripts to do the job, here is the result as suggested by the answers:

i have installed sudo
i have added this to /etc/sudoers file:

nemo ALL = NOPASSWD: /usr/bin/dbus-send

then i did create two script, one for on and one for off with content from zielos
in situations i used script action with:

bash /path to on script
bash /path to off script (at end of situation)

The preferred method would be to install sudo on the phone, and to use it to execute scripts/commands with root privileges. I did that, and it works very well.

Why would you want to do this?
The app is designed to run as normal user and if it needs root rights it should use some service or helper binary.
The only thing you might achieve e.g. is to write some config files as root and cannot access them later via normal user…

Giving password in command line is definitely not a good approach as everything would be stored in .bash_history…
but you might do so by echoing the password and pipe it to the command (on purpose not written out explicitly :wink: )

1 Like

Exactly. “Some service or helper binary” is sudo. Sudo has been created for that purpose.

I don’t know what exactly the problem is that you’re trying to solve, but I have a hunch that it might be be sufficient to do chown :privileged and chmod g+s on the executable and then run it normally from the app grid. I wouldn’t recommend running apps with root privileges.

1 Like

goal is to switch on/ff airplane.mode.
i uswd to.have a script, but lost it

To enable flight mode as an action in Situations app, use the following command:
sudo /usr/bin/dbus-send --system --dest=com.nokia.mce --print-reply /com/nokia/mce/request com.nokia.mce.request.req_radio_states_change uint32:0 uint32:1

To switch back to normal mode (disable flight mode):
sudo /usr/bin/dbus-send --system --dest=com.nokia.mce --print-reply /com/nokia/mce/request com.nokia.mce.request.req_radio_states_change uint32:1 uint32:1

Again, sudo is the only suitable method for this kind of requirement. All other hacks, such as suid-executables, are just hacks. One can use them on a mobile phone, but never ever on a real unix system.

1 Like

AFAICT having privileged egid should be enough for switching airplane mode on and off, and it’s so much safer than running as root.

1 Like

when i run chown i get operation not permitted, with devel-su

i did try to do it not on the app but on the script file

in terminal it works as expected, but
i have following problems:

a) i can not make the script containing the call executable using +x. no idea why.
ok, i use now bash instead of making the file executable

b)
when i run the call as is in situations, nothing happens

c) when i run it from terminal, the password query still pops up.
i have installed sudo and i did manually add nemo to sudoer file

Personnaly, I have installed mcetools.
to enable flight-mode: sudo mcetool -R master
to disable it: sudo mcetool -r master

Or install connman-tools:
to enable flight-mode: sudo connmanctl enable offline
to disable it: sudo connmanctl disable offline

it seems that my main problem at the moment is sudo.
i have installed it but not properly configured ?!

i have added nemo to /etc/sudoers like:

nemo ALL=(ALL) ALL

but it still prompts for …

It’s normal behavior. The line you put authorizes user ‘nemo’ to call ‘sudo’ but with ‘nemo’ passwd.
You could put for example:
nemo ALL= (ALL) NOPASSWD: /usr/bin/connmanctl

thanks, did update the question …

AFAICT setgid doesn’t work with scripts, you have to do that with the executable itself. And of course you need to have permissions to set that bit. Or the executable could be already installed that way with %attr(2755,root,privileged) in the spec, that’s what I would do.