Multi Switch Shutdown Script!
-
@Ranma you can try to edit
$HOME/.bashrc
and play around with it a bit.
The reason for showing the terminal is that the multi_switch script terminates ES and you will be set back to terminal. Maybe it helps to just add a clear command at the end of .bashrc -
@cyperghost Thanks so much for replying. Could I ask, what would be the best way to do this? I can find a number of commands on the internet but I'm not sure of the best one to try. I've been using Linux for some time but never had to edit ./bashrc at any time in the past so my knowledge is non-existent I'm afraid.
-
@Ranma To be true I have not a real clue about this topic, too. I never ran RetroPie as complete hidden software.
Best way to accomplish this task is to usenano $HOME/.bashrc
then addclear
as last command. This will likely reduce your screen to just the prompt. Maybe @mitu can tell how to redirect the complete terminal tty1 to tty3 or so ;)The clear command gots the advantage that it does not break anything on your current setup. So I consider it as ("breakfail"-)save solution.
-
@cyperghost Excellent, thanks for replying. I added a simple clear at the end of the file and you're right - there's just the login prompt onscreen now. If there's a way to hide that too, that would be even better. Many thanks for your help. :-)
-
@cyperghost hello, i use the nespi+ case, 3b+ but no retropie. the scripts i found so far only work with emulationstation but not if you run console. could you add shutdown now for power and reboot for reset with the led? i tried myself but too much stuff going on in the nespi case for me to finish it within a year and i dont want to mess up your script.
would it be possible to add a function in case shutdown is stuck cause no es is running? it could work down other shutdown / reboot options and your script your get even more universal?
-
@mrnebu said in Multi Switch Shutdown Script!:
would it be possible to add a function in case shutdown is stuck cause no es is running?
That's already possible within the script. For the NESPi+ you see the lines
# Initiate Shutdown per ES es_action --ES-CLOSEEMU es_action --ES-POWEROFF # If ES isn't running use regular shutoff sudo poweroff
So indeed if ES is not running it already uses the regular poweroff. On the other hand you can use this script to read status of ES or running emulators and can then decide on your own what to do. So I think it is as flexible as you descripe and will cover a lot of usescases if you know how to use. So I made created a usecase for python here and also RetroFlag mentioned the script.
-
-
@Rion said in Multi Switch Shutdown Script!:
taughts
The early bird catches the ... something.
Now, if you want the prompt to disappear and you already modified the
.bashrc
file, just add as last lines of the file:export PS1="" tput civis
and then logout.
-
@mitu Thank you Mr Bash Shell Wizard!
-
-
I've modified the python script from this post, which calls the Multiswitch script, to add several reset behaviors with generic buttons connected to the GPIO.
Assuming two buttons, the behavior is as follows:
- One button (connected to GPIO 3) acts as shutdown (and power up)
- The other button resets the system. One short press, quits the current emulator or restarts emulationstation. One long press (3 sec) restarts the system.
I attach here the code just in case someone finds it useful (it assumes multi_switch.sh is in /home/pi). You may add this as a python call to /opt/retropie/configs/all/autostart.sh
#!/usr/bin/env python3 from gpiozero import Button, LED import os from signal import pause import subprocess import time powerPin = 3 resetPin = 2 resetMinSeconds = 2 #functions that handle button events def when_pressed(): output = int(subprocess.check_output(['/home/pi/multi_switch.sh', '--es-pid'])) if output: os.system("/home/pi/multi_switch.sh --es-poweroff") else: os.system("sudo shutdown -h now") def reboot(): start_time=time.time() diff=0 while rebootBtn.is_active and (diff < resetMinSeconds): now_time=time.time() diff=-start_time+now_time output = int(subprocess.check_output(['/home/pi/multi_switch.sh', '--es-pid'])) output_rc = int(subprocess.check_output(['/home/pi/multi_switch.sh', '--rc-pid'])) if (diff > resetMinSeconds): if output: os.system("/home/pi/multi_switch.sh --es-reboot") else: os.system("sudo reboot") else: if output_rc: os.system("/home/pi/multi_switch.sh --closeemu") elif output: os.system("/home/pi/multi_switch.sh --es-restart") else: os.system("sudo reboot") btn = Button(powerPin) rebootBtn = Button(resetPin) rebootBtn.when_pressed = reboot btn.when_pressed = when_pressed pause()
-
@janderclander14 Hehe ;) Nicely done
-
@janderclander14 I've done some changes to the python script for some other system. To get rid of the pathes I added
#get script directory scriptDir = os.path.dirname(os.path.realpath(__file__))
So the directory from the python script is catched. Assuming the python and the bash script are stored in the same directory we can use....
os.chdir(scriptDir) .. .. elif output: os.system("./multi_switch.sh --es-restart")
I was fixed to to
/opt/RetroFlag
because RetroFlag use as default in the installer and so I use this path to overwrite their script. But congrats you are the first one who activly uses the provided output to create a new shutdown script. Such it was intended to do ;) -
@cyperghost Certainly, using relative directories is always better. And thanks to you for the script! It just had all the functionalities one would need.
-
@cyperghost Would it possible to adapt your script to work with the new RetroFlag GPi case? It only has a shutdown switch (no reset function). This is the script that is currently supplied by retroflag:
#!/usr/bin/env python3 from gpiozero import Button, LED import os from signal import pause powerPin = 26 powerenPin = 27 hold = 1 power = LED(powerenPin) power.on() #functions that handle button events def when_pressed(): os.system("sudo killall emulationstation && sleep 5s && sudo shutdown -h now") btn = Button(powerPin, hold_time=hold) btn.when_pressed = when_pressed pause()
As you can see they are just using a "sleep" function to handle saving metadata which is not ideal.
-
@quicksilver Yes .... the os.system call has to be changed.
os.system("bash /path/to/multi_switch/multi_switch.sh --es-poweroff")
This will try to close all open emulators and then shutdown the system (after all metadata is saved)
-
@cyperghost That was easy and it works like a charm! Thank you my friend!
-
@cyperghost is there a way to get your script to shutdown if you exit emulation station to the terminal? Or if emulation station crashes or something?
-
@quicksilver said in Multi Switch Shutdown Script!:
is there a way to get your script to shutdown if you exit emulation station to the terminal?
Therefore you can use
.bashrc
from your home directory.
Just add a poweroff command and if you go to terminal the command will be executed.Or if emulation station crashes or something?
You would ask for the PID of Emulationstation simply with
pidof emulationstation
You will obtain the one from the binary and as long this is alive you know ES is running. If there is a change in the PID or the status of SIGNAL has changed you can assume that there someting happend to ES. To determine if it a user action (Reboot, Shutdown...) you watch for files placed into/tmp
dirThe files are
/tmp/es-sysrestart
for sytem wide reboot/tmp/es-restart
for just restarting ES/tmp/es-shutdown
for poweroff
So to answer your question if my script can do this .... only for the
.bashrc
part that is really no rocket science and asudo poweroff
command call would be more effictive.Be aware to not shoot in your own leg with this!
-
Just wanted to say thanks for this awesome script. After (unsuccessfully) messing around with 'dtoverlay' in config.txt and some years old non-functioning auto-installed stuff, I finally have a single button safe shutdown for ES. Thanks to cyperghost and all involved!
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.