Dietpi + Kodi + (Retroarch or retropie) how?

I currently have a DietPi with Kodi working perfectly, along with an Argon Case V3 with NVMe and an IR sensor. I’ve also added an IR remote, and everything works perfectly. But now I want to add emulation functionality. I’d like it so that when I press the power button in Kodi, it prompts me to exit or shut down and go to the game system, and then return to Kodi when I exit the game. That’s the only thing I’m missing to make this a proper multimedia center. Any help would be greatly appreciated. Thanks.

So Kodi and the emulation station each work fine on their own so far?

Shutdown in Kodi means system shutdown, so there is no way to start the emulation station at this point. But when just exiting Kodi, there would be a way: a script which starts both programs in a loop:

#/bin/dash -e
while :
do
kodi
retropie
done

More a template than production ready:

  • Endless loop, requires kodi and retropie (I don’t know the executable name) to run in foreground. For kodi this is the case.
  • The -e flag lets the loop exit if any of the two exits with an error code, to prevent a short circuit in case of errors. AFAIK kodi exists without error code when selecting exit from its GUI, Retropie or Retroarch would need to do the same.
  • If you really aim to shutdown, it might be a bit ugly, like Retripie starting while shutdown procedure is happening. And no easy way to exit the loop without error or shutdown from the same console. You could add some sleep or read -p between the commands, so give some time to hit CTRL+C to exit the loop, or require input to continue.

You could put this into /var/lib/dietpi/postboot.d or as dietpi-autostart custom foreground script, or into ~/.bashrc to call it on login.