Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: levell3r on June 09, 2020, 06:23:55 AM

Title: Using fe.plugin_command_bg to run SUDO
Post by: levell3r on June 09, 2020, 06:23:55 AM
Hi All,
I have an executable that needs to be run with sudo as it needs to use the hardware pulse generator.
But I cannot get fe.plugin_command_bg to pass a SUDO command succesfully.

If I pass the flag that lets it run without elevated privilege's it works, so I know everything else is okay.




Code: [Select]
fe.add_transition_callback( "onTransition" );

function onTransition( ttype, var, ttime ) {


switch ( ttype )
{
case Transition.ToGame:
case Transition.ToNewSelection:
case Transition.FromGame:


     fe.plugin_command_bg( "led-image-viewer","--led-no-hardware-pulse --led-rows=32 --led-cols=64 --led-chain=2 --led-slowdown-gpio=3 --led-brightness=50 --led-pwm-bits=9 --led-limit-refresh=50 --led-scan-mode=0 --led-pwm-lsb-nanoseconds=200 /home/pi/GFXdirectory*.png -C");
break;

}

return false; // must return false
}


Am I overlooking something related to fe.plugin_command_bg and SUDO?
 
Title: Re: Using fe.plugin_command_bg to run SUDO
Post by: zpaolo11x on June 09, 2020, 06:43:04 AM
I did some experiments a couple of weeks ago with the shutdown command and I managed to make it work, let's say your command is

Code: [Select]
sudo shutdown now -h now
the command was something like this:

Code: [Select]
fe.plugin_command_bg ("sudo", "shutdown -h now")
like if shutdown was used as a parameter.

Alternatively you can try with the "system" function, which is just

Code: [Select]
system ("your command string")
but this, on windows, sometimes raises and quickly hides a command window (but since you are talking about sudo I guess you are not on windows ;) )
Title: Re: Using fe.plugin_command_bg to run SUDO
Post by: levell3r on June 09, 2020, 07:02:16 AM
ITS WORKED!
Adding the executable as the argument did it.
Have tried system() and it really chewed the Pi up.

Now to pass some magic tokens to generate the path for images.



Thanks for the advice.
Title: Re: Using fe.plugin_command_bg to run SUDO
Post by: keilmillerjr on June 09, 2020, 12:14:06 PM
You can create an alias: https://wiki.archlinux.org/index.php/Allow_users_to_shutdown

Why do you need sudo?
Title: Re: Using fe.plugin_command_bg to run SUDO
Post by: levell3r on June 09, 2020, 12:50:43 PM
Hi,
I'm trying to run hzeller rgb-led driver with the marquee path set using a magic token function.

I have minimal coding experience but could normally frankenstein stuff together.



Code: [Select]
     fe.plugin_command_bg( "sudo", "led-image-viewer --led-rows=32 --led-cols=64 --led-chain=2 --led-slowdown-gpio=3 --led-brightness=50 --led-pwm-bits=9 --led-limit-refresh=50 --led-scan-mode=0 --led-pwm-lsb-nanoseconds=200 -C " + "/home/pi/RetroPie/roms/" + fe.game_info( "[!emuinfo]") + "/marquee/" + fe.game_info( "[!gameinfo]") + ".png"); break;
Title: Re: Using fe.plugin_command_bg to run SUDO
Post by: levell3r on June 09, 2020, 01:14:17 PM
I think i'm getting close.



Code: [Select]
fe.add_transition_callback("onTransition");

function onTransition( ttype, var, ttime )
{
   if ( ttype == Transition.ToNewSelection )

  {
    local argString = "";
    fe.plugin_command_bg( "sudo", "led-image-viewer --led-rows=32 --led-cols=64 --led-chain=2 --led-slowdown-gpio=3 --led-brightness=50 --led-pwm-bits=9 --led-limit-refresh=50 --led-scan-mode=0 --led-pwm-lsb-nanoseconds=200 -C /home/pi/RetroPie/roms/" + fe.game_info( Info.Emulator ) + "/marquee/" + fe.game_info( Info.Title ) + ".png" );
  }
}


The above is working except it throws a 'Parameter word expansion failed' error. I think because its passing the rom name which has spaces in to the file path...



error log..

Quote
*** Initializing display: 'Capcom Classics'
 - Loaded master romlist 'Arcade' in 241 ms (96 entries kept, 9700 discarded)
 - Constructed 1 filters in 0 ms (96 comparisons)
Parameter word expansion failed. [led-image-viewer --led-rows=32 --led-cols=64 --led-chain=2 --led-slowdown-gpio=3 --led-brightness=50 --led-pwm-bits=9 --led-limit-refresh=50 --led-scan-mode=0 --led-pwm-lsb-nanoseconds=200 -C /home/pi/RetroPie/roms/Arcade/marquee/X-Men Children of the Atom (Euro 950331).png].