Mausberry Shutdown Script Doesn't Save Metadata
-
Good stuff! So just to clarify, that's saving the nonvolatile RAM right? Not creating a Save State? Because of RetroAchievments, I typically just leave my RetroArch in Hardcore mode, which disables Saves States and Cheats.
Sorry about last night and my headache. I wasn't fully following the discussion between @cyperghost and @meleu. When I get a chance, I will try it with the command:
pkill -f "$(sed -n 4p /dev/shm/runcommand.info)"
-
@hansolo77 yes just the sram. Not savestates. By default the sram stays in RAM until you exit. This just checks the sram every x seconds and sees if there is a change. If so, it writes to disk.
-
That added line to the script seems to break the script. I added the 1.3 changes (using the original
pkill retroarch > /dev/null 2>&1
bit), then I changed it to thepkill -f "$(sed -n 4p /dev/shm/runcommand.info)"
. For some reason now, whenever I press the power button nothing happens. At first I thought it was because thepkill
command was nested inside theif
statement. When I SSH'd into the system and checkedtop
, ES was no longer running when RetroArch was. So the new additions to the script weren't getting picked up. I moved it (as a test) outsideif
functions. Still nothing happened. I've experimented with doingsudo reboot
from the SSH terminal as well as via ES shutdown (from the menu). In both cases, the power button still doesn't work. I can, however, power the system on from a complete power plug pull via the button, so I know the switch is still good. You sure that's the right command? -
OK, further "looking around"... the original script (v1.2) wasn't working either. So I went back to the unedited v0.0 (the one Mausberry has you install). That one didn't work either! So I checked out the install script, and saw they're adding a line to
rc.local
. I'm not sure what that file is, but when I edited it, it had 2 instances of the script path/etc/switch.sh
in there. I took one out and rebooted. Now the original script is working right. Gonna try putting in the new changes and see if that was my problem.EDIT Still a no-go on that 1.3 edit. :(
EDIT 2 Facepalm - I think it might be a file properties issue now... I rechecked the Mausberry install script and noticed they're doing a
chmod +777
on the script prior to rebooting. Since I already had a working script, I moved it to a backup file before making changes. I saved the changes to a new file and renamed it to be what it should be. But I suspect the+777
isn't there. So I added that bit in the terminal and just rebooted. The system now shuts down correctly (using the 1.2 script). Now testing 1.3.EDIT 3 Ha! That was the trick. But it's not saving the metadata. It might be that it's not giving it enough time to return to ES before cutting the power... When I hit the button, it turns off the emulator, and I see the RunCommand box (haven't set up the launching images yet). At the bottom of the screen there is a line that says "Terminated", then the system turns off..
EDIT 4 I don't think this script in it's current form works well. I tried adding a second to the sleep timer. Then tried to test the script just as is before actually launching a game. The script launches, but the system never shuts down. ES closes, but that's it. I don't know if it's getting hung up on the
sleep
or what. But the only way I can recover is by pulling the plug. With the 2 added (v1.3) lines # commented out, the system fully powers down again. I think there needs to be additional lines of code to include an if/then/else. IF emulator is running, THEN kill and wait, ELSE shutdown ES. But will that even execute if an emulator isn't running? Would it need to read out as "IF emulator, THEN kill emulator and wait, THEN kill ES.. ELSE kill ES"?PS - I'm done for the night. :)
-
So I think it we should provide and maintain v1.2 only!
Get the version for Mausberry circuits shutdowns from hereThank @hansolo77 for testing this
This script will properly shutdown ES and saves it's metadata if you press power button on your mausberry circuit!- Metadata is needed to save scraped games, favorites and last played record upon next reboot
- This script will work if your are in EmulationsStation
- This script will not properly save metadata if you shutdown during gameplay or if your RPi is locked (So return to ES by pressing start+select on your gampad and then shutdown!)
# End Emulationstation if condition of running binary is true # v1.0 07/21/17 by cyperghost - Inital run # v1.1 07/22/17 - Added chown command to set right user permission for creating es-shutdown # v1.2 07/23/17 - Some small improvments, easier to maintain, removed echo, removed else branch # greetings @pjft for his famous favorits and @meleu for the RegEx sniplet espid=$( pgrep -f "/opt/retropie/supplementary/.*/emulationstation([^.]|$)" ) # detect PID of ES binary only if [ "$espid" ]; then # Condition: PID is not equal 0 or empty then use ES shutdown touch /tmp/es-shutdown && chown pi:pi /tmp/es-shutdown #v1.1 Change file permission of es-shutdown to user:group pi:pi kill $espid #v1.2 use kill@detected PID - easier to maintain now! exit fi # End Emulationstation if condition of running binary is true
-
EXPERIMENTAL!!!
Converted from @meleu to kill all emulators
It worked (saved recently used games) for me in SSH but I've no chance to test >> lack of mausberry!# End Emulationstation if condition of running binary is true (Shotgun-version - no support!) # v1.0 07/21/17 by cyperghost - Inital run # v1.1 07/22/17 - Added chown command to set right user permission for creating es-shutdown # v1.2 07/23/17 - Some small improvments, easier to maintain, removed echo, removed else branch # v1.4 07/25/17 - Shotgun method to terminate all launchs by runcommand (not maintained, use v1.2 for support) # greetings @pjft for his famous favorits and @meleu for the RegEx sniplet espid=$( pgrep -f "/opt/retropie/supplementary/.*/emulationstation([^.]|$)" ) # detect PID of ES binary only if [ "$espid" ]; then #### Experimental part #### IFS=" " set – $( sed -n 4p /dev/shm/runcommand.info ) > /dev/null 2>&1 pkill $2 && sleep 4 # v1.4 Sleeptimer to give ES chance to save XML filestate (untestested) #### Experimental part #### touch /tmp/es-shutdown && chown pi:pi /tmp/es-shutdown # v1.1 Change file permission of es-shutdown to user:group pi:pi kill $espid # v1.2 use kill@detected PID - easier to maintain now! exit fi
-
@cyperghost some notes
- the indentation can be improved :)
- the default
IFS
is space, tab and newline. I think there's no need to set it as space - I'm not getting the reason why you are messing with the
set
command (unnecessary complexity)...
the suggested command doesn't work for you?
pkill -f "$(sed -n 4p /dev/shm/runcommand.info)"
-
@meleu yes
pkill -f "$(sed -n 4p /dev/shm/runcommand.info)"
Does not work. So you need to extract just binary call... I tested with retroarch, glide64 and zdoom. All were prober working byset
-command -
@cyperghost said in Mausberry Shutdown Script Doesn't Save Metadata:
@meleu yes
pkill -f "$(sed -n 4p /dev/shm/runcommand.info)"
Does not work.weird. I'm not able to test on my actual RetroPie, but look the test I've made:
[PROMPT]$ sleep 1000 & [1] 8648 [PROMPT]$ cat test.info 1st line 2nd line 3rd line sleep 1000 bla bla bla [PROMPT]$ pkill -f "$(sed -n 4p test.info)" [1]+ Terminated sleep 1000
But I noticed an issue when the file to look for the 4th line doesn't exist... then my suggestion is to use this
[[ -f /dev/shm/runcommand.info ]] && pkill -f "$(sed -n 4p /dev/shm/runcommand.info)"
Can you test it on a real RetroPie setup?
-
@meleu Not now ... Have to work :)
Cya mate! -
@cyperghost I found the problem: that line from
runcommand.info
has some double quotes wich is confusing thepkill
. Here's my current solution:rcinfo=/dev/shm/runcommand.info [[ -f "$rcinfo" ]] && pkill -f -9 "$(sed -n 4p "$rcinfo" | cut -d' ' -f1)"
I tested on my retropie here and it seems to work. Please test it when you have a chance.
Cheers!
-
You guys are just talking gibberish again. For somebody who's unfamiliar with all of this, I'm completely lost. RetroPie is only my 2nd ever Pi project, and really only my first exposure to the scripting side of it. I'm eager to learn, but throwing out seemingly random lines of code without reference or instruction on where to place it doesn't help me any. :) No biggie, I'll get there. I'm just totally unfamiliar with the commands.
set
sed
,IFS
.. totally new to me. I only just learned abouttop
like 4 days ago. ^_^So tomorrow after work, would you rather I test @cyperghost's v1.4 or replace that section with @meleu's? Or would it be better to just wait and let ya'll hash it out some more?
-
@hansolo77 haha... sorry for the nerdy stuff. :)
my suggestion is to try this:
espid=$(pgrep -f "/opt/retropie/supplementary/.*/emulationstation([^.]|$)") if [ "$espid" ]; then [[ -f "/dev/shm/runcommand.info" ]] \ && pkill -f -9 "$(sed -n 4p "/dev/shm/runcommand.info" | cut -d' ' -f1)" \ && sleep 4 touch /tmp/es-shutdown && chown pi:pi /tmp/es-shutdown kill $espid fi
-
Ok cool. I'm going to bed soon so I will test this tomorrow when I get off work. If not right away, I'm off Thursday, so plenty of time then.
-
@meleu
You can even improve :)Edit
runcommand-onend.sh
and addsudo rm /dev/shm/runcommand.info
or make PR to runcommand.sh :)
Because runcommand.info isn't removed if emulator ends by start+select button :) It isn't really needed but it's a nice cleanup and definates the addition to the GPIO script you made with more sense. -
@cyperghost it can be useful for debugging. I prefer to keep it even after the emulator has finished.
-
@meleu And why do you check presence of runcommand.info in your script? Don't get me wrong but I think the filecheck only makes sense if you remove that after emulator call ends? Because you will always run the "sleep 4"-command even if you are only in ES :)
-
@cyperghost because if the file doesn't exist that
sed
will fail and print nothing (empty string).Just for fun do the following
- save all important file you have open.
- perform this command:
pkill -f ""
- cry (well, if you saved the files you don't have to cry. as I didn't saved, I cried)
Explaining: using an empty string as the pattern matches "everything". And the result is pkilling every single process owned by the pkiller!
I noticed it on an unpleasant way. :)
-
@meleu Okay ... what about this one?
It's pretty save and finds out PID of every emulator :)#!/bin/bash emucall=$(sed -n 4p /dev/shm/runcommand.info) emupid=${emucall#* } pos=$(expr ${#emucall} - ${#emupid}) emupid=$(pgrep -f ${emucall:0:$pos}) kill $emupid
Then if PID is a true value kill first the emulator and then kill ES in seconds instance... Thank your for every suggestions - I learn really a lot of your examples!
-
@cyperghost said in Mausberry Shutdown Script Doesn't Save Metadata:
@meleu Okay ... what about this one?
#!/bin/bash emucall=$(sed -n 4p /dev/shm/runcommand.info) emupid=${emucall#* } pos=$(expr ${#emucall} - ${#emupid}) emupid=$(pgrep -f ${emucall:0:$pos}) kill $emupid
Wow! It's a bit complex, isn't it?
Yeah, using parameter substitution is a good solution here. But I would simplify it with this:
emucall="$(sed -n 4p /dev/shm/runcommand.info)" [[ -n "$emucall" ]] && pkill -f "${emucall% *}"
By the way, sometimes I feel like we are messing @hansolo77 's thread with all those bash snippets. I'm going t open a bash thread for us. :-)
EDIT: topic created https://retropie.org.uk/forum/topic/11900/shell-scripting-topic
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.