Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added generic save shutdown method for RetroPie #6

Open
wants to merge 114 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
6f2367f
Added generic shutdown method
crcerror Apr 26, 2018
0134841
Added generic safe shutdown (save metadata!)
crcerror Apr 26, 2018
b3dbd9a
v 0.41
crcerror Apr 26, 2018
143622f
Save Shutdown for RetroPie - never loose data
crcerror Apr 27, 2018
c1e725e
Update SafeShutdown.py
crcerror Jul 2, 2018
4c44b2f
More natural behaviour
crcerror Jul 3, 2018
daa4347
Update README.md
crcerror Jul 3, 2018
fd39005
Update install.sh
crcerror Jul 3, 2018
ba5e2a3
Delete recalbox_install.sh
crcerror Jul 7, 2018
5d75f6b
Delete recalbox_SafeShutdown.py
crcerror Jul 7, 2018
a996b24
Update README.md
crcerror Jul 7, 2018
fd25e61
Update README.md
crcerror Jul 7, 2018
fdf1fe4
Update README.md
crcerror Jul 7, 2018
9f3378b
Support RPi 3B+ now
crcerror Sep 13, 2018
73feef0
Ignore if the directory already exists for install over RetroFlag ver…
Nov 14, 2018
567b9cd
Added mode for RPi 3B+
crcerror Nov 14, 2018
8872c6c
Merge pull request #1 from KlfJoat/bug-install-mkdir
crcerror Feb 6, 2019
f8a86ce
v 0.85
crcerror Feb 8, 2019
a006585
Updated installer
crcerror Feb 23, 2019
0b39d20
install.sh updated
crcerror Feb 23, 2019
085e5f8
install.sh updated
crcerror Feb 23, 2019
2937fd8
Create recalbox_SafeShutdown.py
crcerror Mar 19, 2019
aaa1cbd
Create recalbox_SafeShutdown.sh
crcerror Mar 19, 2019
f4f458c
Create recalbox_install.sh
crcerror Mar 19, 2019
819b1bb
Create install_batocera.sh
crcerror Mar 19, 2019
2b994fd
Update install_batocera.sh
crcerror Mar 19, 2019
036d59c
Update install_batocera.sh
crcerror Mar 19, 2019
6455019
Update install_batocera.sh
crcerror Mar 19, 2019
41d4f9c
Update install_batocera.sh
crcerror Mar 19, 2019
d79fa3d
Update install_batocera.sh
crcerror Mar 19, 2019
f827643
Update install_batocera.sh
crcerror Mar 19, 2019
1e26ef6
Finally done
crcerror Mar 19, 2019
3660059
Update install_batocera.sh
crcerror Mar 19, 2019
d4a2a30
Update install_batocera.sh
crcerror Mar 19, 2019
962927e
Delete install_batocera.sh
crcerror Mar 19, 2019
a6685df
Create install_batocera.sh
crcerror Mar 19, 2019
ed7a38b
Update install_batocera.sh
crcerror Mar 19, 2019
2c6b6df
Delete install_batocera.sh
crcerror Mar 19, 2019
206fb3d
Create install_recalbox.sh
crcerror Mar 19, 2019
462fd9f
Update install_recalbox.sh
crcerror Mar 19, 2019
d489b24
Update install_recalbox.sh
crcerror Mar 19, 2019
6c4f8df
Update install_recalbox.sh
crcerror Mar 19, 2019
5933cae
Update recalbox_install.sh
crcerror Mar 19, 2019
72e43ab
Update recalbox_install.sh
crcerror Mar 19, 2019
71b416c
Create install_batocera.sh
crcerror Mar 19, 2019
706032c
Update recalbox_install.sh
crcerror Mar 19, 2019
e540b0f
Update recalbox_install.sh
crcerror Mar 19, 2019
4eecb16
Create batocera_SafeShutdown.py
crcerror Mar 19, 2019
f6b6d22
Delete batocera_SafeShutdown.py
crcerror Mar 19, 2019
87a1db6
Create batocera_SafeShutdown.py
crcerror Mar 19, 2019
10593cd
Update recalbox_install.sh
crcerror Mar 19, 2019
1c367dc
fixed indentation
crcerror Mar 19, 2019
51baed6
fixed indentation
crcerror Mar 19, 2019
2d27d10
Update install_recalbox.sh
crcerror Mar 20, 2019
3b000c9
added scriptDir argument
crcerror Mar 20, 2019
298a5d3
Delete batocera_SafeShutdown.py
crcerror Mar 20, 2019
76ff5e5
Updated installer script
crcerror Mar 20, 2019
6df426b
Update install_recalbox.sh
crcerror Mar 20, 2019
59dbc21
Update install_batocera.sh
crcerror Mar 20, 2019
cf838f1
Fixed pathes to execute files
crcerror Mar 20, 2019
431ceaf
Fixed get several IPs
crcerror Mar 20, 2019
5af4f22
Final!
crcerror Mar 20, 2019
f8f9415
Final!
crcerror Mar 20, 2019
44d1a68
Added --kodi switch
crcerror Mar 21, 2019
deefc55
Update README.md
crcerror Mar 21, 2019
5c25c9b
Update README.md
crcerror Mar 22, 2019
06a81e2
Update README.md
crcerror Mar 29, 2019
9c169cd
Fix installation
crcerror Apr 25, 2019
2456ea7
Enabled UART again
crcerror Apr 28, 2019
03739ff
Update recalbox_SafeShutdown.py
crcerror May 20, 2019
ef00416
--shutdown parameter
crcerror May 21, 2019
9f202c7
Update recalbox_SafeShutdown.py
crcerror May 21, 2019
786f034
got back old version
crcerror May 24, 2019
3ee28f7
Save Metadata in BATO 5.22 systems now
crcerror May 26, 2019
248ea97
Save Metadata in BATOCERA 5.22 builds now
crcerror May 26, 2019
071cc31
Save Metadata on BATOCERA 5.22 builds now
crcerror May 26, 2019
4dc7c03
Added SIGTERM to some emulators
crcerror Jun 4, 2019
2f6a5d9
need BATCERA 5.24 and above
crcerror Sep 28, 2019
db6135e
BATOCERA 5.24 needed at least
crcerror Sep 28, 2019
ac2aa4b
Create batocera_install.sh
crcerror Sep 28, 2019
5f77a69
Updated for BATOCERA 5.24
crcerror Sep 28, 2019
ccf8080
BATOCERA 5.24 needed for this
crcerror Sep 28, 2019
ca26e31
BATOCERA 5.24 at least needed
crcerror Sep 28, 2019
2ea9c90
BATOCERA 5.24 at least needed
crcerror Sep 28, 2019
84688e2
BATOCERA 5.24 (dev 10102019) and beyond
crcerror Oct 10, 2019
fc94a09
Update README.md
crcerror Oct 11, 2019
71e6e9b
Update README.md
crcerror Oct 11, 2019
4828efb
BATOCERA 5.24 (dev 10102019) and beyond
crcerror Oct 13, 2019
55cdf2a
py: BATOCERA 5.24 (dev 10102019) and beyond
crcerror Oct 13, 2019
7d64f8b
BATOCERA 5.25 support added
crcerror Nov 24, 2019
85d9811
Create install.sh
crcerror Dec 20, 2019
9e09812
Create SafeShutdown.py
crcerror Dec 20, 2019
1ac3ce4
Update install.sh
crcerror Dec 20, 2019
e34cd65
Create batocera_install.sh
crcerror Dec 20, 2019
4a11d28
Create install_gpi.sh
crcerror Dec 20, 2019
37a2f97
Create install_gpi_batocera.sh
crcerror Dec 20, 2019
f1d3e77
Update README.md
crcerror Dec 21, 2019
352c167
Create uninstall_all.sh
crcerror Jan 2, 2020
df228b6
Update for GPi
crcerror Jan 2, 2020
fd4c0ff
Added uninstaller
crcerror Jan 3, 2020
ac2db56
BATOCERA: fixed installer GPi
crcerror Jan 6, 2020
1dae2a2
small fixes to README
NetizenAbel Jan 11, 2020
24a2b9d
Merge pull request #3 from kashaiahyah85/patch-1
crcerror Jan 12, 2020
6f6317a
Fixed install.sh
DeeKay-Deluxe Feb 1, 2020
260db15
Merge pull request #4 from DeeKay-Deluxe/master
crcerror Feb 3, 2020
b2b9514
Support for NESPi4 added
crcerror Aug 22, 2020
9409674
Added NESPi4 support
crcerror Aug 22, 2020
d20a7a3
Added NESPi4 support
crcerror Aug 22, 2020
160ff8e
NESPi4 support added
crcerror Aug 22, 2020
ce31fe7
Added NESPi4 support
crcerror Aug 22, 2020
dc95135
Added best NESPi4 support
crcerror Aug 22, 2020
1ac6e53
Added retroflag NESPi4 removal
crcerror Aug 22, 2020
e4bc718
Update batocera_install.sh
crcerror Dec 28, 2020
2519935
Added python3 and python removal method
crcerror Jul 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 93 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,110 @@
# retroflag-picase
RetroFlag Pi-Case Safe Shutdown

**Section 1**\
Installers for NesPi+, MegaPi, SuperPi cases and (since 2020/08/22) **NESPI4**
Support for RetroPie, RecalBox and BATOCERA

**Section 2**\
Installer for the GPi case\
Support for RetroPie and BATOCERA

**Section 3**\
Uninstall for all systems and all cases\
This means uninstaller for NesPi+, MegaPi, SuperPi and GPi cases\
for RetroPie, RecalBox and BATOCERA

## Section 1. RetroFlag Pi-Case+ Safe Shutdown

#### Turn switch "SAFE SHUTDOWN" on PCB to ON position.

![Safe Shutdown Switch](http://retroflag.com/images/nespi_case+/safe_shutdown.jpg "Safe Shutdown Switch")

#### **Multi Switch Shutdown**
with advanced shutdown features for more natural behaviour:
* If you press restart if emulator is currently running, then you will be kicked back to ES main menu
* If you press restart in ES main screen, ES will be restartet (no reboot!), good for quick saving metadata or internal saves.
* If you press power-off then Raspberry will shutdown

All metadata is always saved

Turn switch "SAFE SHUTDOWN" on PCB to ON.

--------------------

Example for RetroPie:
#### Example for **RetroPie:**
1. Make sure internet connected.
2. Make sure keyboard connected.
3. Press F4 enter terminal.
4. In the terminal, type the one-line command below(Case sensitive):
4. In the terminal, type the one-line command below (case sensitive):

wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/install.sh" | sudo bash
**`wget -O - "https://raw.githubusercontent.com/crcerror/retroflag-picase/master/install.sh" | sudo bash`**

--------------------

Example for RecalBox:
#### Example for **RecalBox** and **Batocera:**
1. Make sure internet connected.
2. Make sure keyboard connected.
3. Press F4 first. And then press ALT-F2 enter termial.
4. User:root Password:recalboxroot
5. In the terminal, type the one-line command below(Case sensitive):
4. User: root Password: recalboxroot
5. In the terminal, type the one-line command below (case sensitive):

For Recalbox:\
**`wget -O - "https://raw.githubusercontent.com/crcerror/retroflag-picase/master/install_recalbox.sh" | bash`**

For Batocera:\
**`wget -O - "https://raw.githubusercontent.com/crcerror/retroflag-picase/master/install_batocera.sh" | bash`**

You can edit the python script and add some parameters to the script calls:
```
--restart will RESTART EmulationStation only
--kodi will startup KODI Media Center
--emukill to exit any running EMULATORS
--espid to check if EmulationStation is currently active
--emupid to check if an Emulator is running"

```

## Section 2. RetroFlag GPi-Case Safe Shutdown

#### Turn switch "SAFE SHUTDOWN" on PCB to ON position.

![](http://retroflag.com/images/gpi-case/safe_shutdown.png)

#### **Multi Switch Shutdown**
with advanced shutdown features for more natural behaviour:
1. If you press power-off then Raspberry will shutdown and always save metadata even if you are in an ingame session

All metadata is always saved


--------------------

#### Example for **RetroPie:**
1. Make sure internet connected.
2. Make sure keyboard connected.
3. Press F4 enter terminal.
4. In the terminal, type the one-line command below (case sensitive):

**`wget -O - "https://raw.githubusercontent.com/crcerror/retroflag-picase/master/install_gpi.sh" | sudo bash`**

--------------------

#### Example for **Batocera**
1. Make sure internet connected.
2. Make sure keyboard or SSH connected.
3. User: root Password: linux
4. In the terminal, type the one-line command below (case sensitive):

**`wget -O - "https://raw.githubusercontent.com/crcerror/retroflag-picase/master/install_gpi_batocera.sh" | bash`**

## Section 3. Uninstallers

#### Example for RetroPie
Type in the terminal, type the one-line command below (case sensitive):

**`wget -O - "https://raw.githubusercontent.com/crcerror/retroflag-picase/master/uninstall_all.sh" | sudo bash`**

#### Example for RecalBox and BATOCERA
Type in the terminal, type the one-line command below (case sensitive):

wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/recalbox_install.sh" | bash
**`wget -O - "https://raw.githubusercontent.com/crcerror/retroflag-picase/master/uninstall_all.sh" | bash`**
20 changes: 17 additions & 3 deletions SafeShutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gpiozero import Button, LED
import os
from signal import pause
import subprocess

powerPin = 3
resetPin = 2
Expand All @@ -16,12 +17,25 @@
#functions that handle button events
def when_pressed():
led.blink(.2,.2)
os.system("sudo shutdown -h now")
output = int(subprocess.check_output(['/opt/RetroFlag/multi_switch.sh', '--es-pid']))
if output:
os.system("/opt/RetroFlag/multi_switch.sh --es-poweroff")
else:
os.system("sudo shutdown -h now")

def when_released():
led.on()

def reboot():
os.system("sudo reboot")

output = int(subprocess.check_output(['/opt/RetroFlag/multi_switch.sh', '--es-pid']))
output_rc = int(subprocess.check_output(['/opt/RetroFlag/multi_switch.sh', '--rc-pid']))
if output_rc:
os.system("/opt/RetroFlag/multi_switch.sh --closeemu")
elif output:
os.system("/opt/RetroFlag/multi_switch.sh --es-restart")
else:
os.system("sudo reboot")

btn = Button(powerPin, hold_time=hold)
rebootBtn = Button(resetPin)
rebootBtn.when_pressed = reboot
Expand Down
18 changes: 18 additions & 0 deletions gpi/SafeShutdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/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("/opt/RetroFlag/multi_switch.sh --es-poweroff")

btn = Button(powerPin, hold_time=hold)
btn.when_pressed = when_pressed
pause()
51 changes: 51 additions & 0 deletions gpi/batocera_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
# Retroflag Advanced Shutdown Mod by crcerror
# This is exclusivly for BATOCERA
# Intended to work for BATOCERA versions 5.24
#
# Release Power Button to shutdown your GPi case

version=$(grep -o '^[^ ]*' $HOME/data.version)

# Minimum version of BATOCERA is 5.24 because here batocera-es-swissknife is integrated
# so all versions less then 5.24 will be dropped from further install
if [[ ${version//[^[:digit:]]/} -lt 524 ]]; then
echo "Error!"
echo "Your current version of Batocera is '$version'"
echo "You need at least 5.24 ...."
exit
fi

echo "Welcome to the Safe Shutdown installer..."
echo "Batocera '$version' detected..."
sleep 2

echo "Activate RETROFLAG_GPI in batocera.conf"
batocera-settings set system.power.switch RETROFLAG_GPI
sleep 2
echo; echo

echo "Add Safe Shutdown feature for running emulator instance"
if [[ -f /userdata/system/custom.sh ]]; then
echo
echo "custom.sh is already available ..."
echo "I don't change anything here!"
echo
else
cat > /userdata/system/custom.sh <<_EOF_
#!/bin/bash
# custom.sh - place to /userdata/system
# by cyperghost 23/11/19
#

if [[ \$1 == stop ]]; then
batocera-es-swissknife --emukill
fi
_EOF_

chmod +x /userdata/system/custom.sh
fi

echo "Rebooting in 5 seconds...."
sleep 5
shutdown -r now
54 changes: 54 additions & 0 deletions gpi/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
basewebsite="https://raw.githubusercontent.com/crcerror/retroflag-picase"
sleep 2s
#Step 1) Check if root--------------------------------------
if [[ $EUID -ne 0 ]]; then
echo "Please execute script as root."
exit 1
fi

#-----------------------------------------------------------

#Step 3) Update repository----------------------------------
sudo apt-get update -y

sleep 2s
#-----------------------------------------------------------

#Step 4) Install gpiozero module----------------------------
sudo apt-get install -y python3-gpiozero

sleep 2s
#-----------------------------------------------------------

#Step 5) Download Python script-----------------------------
cd /opt/
mkdir RetroFlag
cd RetroFlag
script=SafeShutdown.py
wget --no-check-certificate "$basewebsite/master/gpi/SafeShutdown.py"
chmod +x SafeShutdown.py
wget --no-check-certificate "$basewebsite/master/multi_switch.sh"
chmod +x multi_switch.sh

#-----------------------------------------------------------
sleep 2s
#Step 6) Enable Python script to run on start up------------
cd /etc/
RC=rc.local

if grep -q "sudo python3 \/opt\/RetroFlag\/SafeShutdown.py \&" "$RC";
then
echo "File /etc/rc.local already configured. Doing nothing."
else
sed -i -e "s/^exit 0/sudo python3 \/opt\/RetroFlag\/SafeShutdown.py \&\n&/g" "$RC"
echo "File /etc/rc.local configured."
fi
#-----------------------------------------------------------

#Step 7) Reboot to apply changes----------------------------
echo "RetroFlag Pi Case installation done. Will now reboot after 3 seconds."
sleep 3s
sudo reboot
#-----------------------------------------------------------

53 changes: 31 additions & 22 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,45 @@ if [[ $EUID -ne 0 ]]; then
fi
#-----------------------------------------------------------

#Step 2) enable UART----------------------------------------
#Step 2) Update repository----------------------------------
sudo apt-get update -y
#-----------------------------------------------------------

#Step 3) disable UART from retroflag install ---------------
cd /boot/
File=config.txt
if grep -q "enable_uart=1" "$File";
if grep -q "^enable_uart=1" "$File";
then
echo "UART already enabled. Doing nothing."
echo "UART is already enabled. Disabeling now!"
echo "Commenting out line - your CPU is not throttled anymore"
sed -i -e "s|^enable_uart=1|#enable_uart=1|" "$File" &> /dev/null
else
echo "enable_uart=1" >> $File
echo "UART enabled."
echo "UART is disabled. CPU is working with full speed"
fi
#-----------------------------------------------------------

#Step 3) Update repository----------------------------------
sudo apt-get update -y
#-----------------------------------------------------------

#Step 4) Install gpiozero module----------------------------
sudo apt-get install -y python3-gpiozero
#-----------------------------------------------------------

#Step 5) Download Python script-----------------------------
cd /opt/
sudo mkdir RetroFlag
sudo mkdir -p RetroFlag
cd /opt/RetroFlag
script=SafeShutdown.py

if [ -e $script ];
then
echo "Script SafeShutdown.py already exists. Doing nothing."
echo "Script SafeShutdown.py already exists. Overwriting file now!"
echo "Downloading ..."
else
wget "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/SafeShutdown.py"
echo "Script will be installed now! Downloading ..."
fi

wget -N -q --show-progress "https://raw.githubusercontent.com/crcerror/retroflag-picase/master/SafeShutdown.py"
wget -N -q --show-progress "https://raw.githubusercontent.com/crcerror/retroflag-picase/master/multi_switch.sh"
chmod +x multi_switch.sh

#-----------------------------------------------------------

#Step 6) Enable Python script to run on start up------------
Expand All @@ -55,17 +62,19 @@ if grep -q "sudo python3 \/opt\/RetroFlag\/SafeShutdown.py \&" "$RC";
fi
#-----------------------------------------------------------

#Step 7) Reboot to apply changes----------------------------
#Step 7) enable overlay file for powercut ---------------
cd /boot/
File=config.txt
if ! grep -q "^dtoverlay=gpio-poweroff,gpiopin=4,active_low=1,input=1" $File; then
echo "Enable overlay file"
echo "# Overlay setup for proper powercut, needed for Retroflag cases" >> "$File"
echo "dtoverlay=gpio-poweroff,gpiopin=4,active_low=1,input=1" >> "$File"
fi

#-----------------------------------------------------------

#Step 8) Reboot to apply changes----------------------------
echo "RetroFlag Pi Case installation done. Will now reboot after 3 seconds."
sleep 3
sudo reboot
#-----------------------------------------------------------









4 changes: 4 additions & 0 deletions install_batocera.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
echo "Downloading install script .... for BATOCERA"
sleep 2
wget -q -O - https://raw.githubusercontent.com/crcerror/retroflag-picase/master/other_os/batocera_install.sh | bash
4 changes: 4 additions & 0 deletions install_gpi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
echo "Downloading install script ...."
sleep 2
wget -q -O - https://raw.githubusercontent.com/crcerror/retroflag-picase/master/gpi/install.sh | bash
4 changes: 4 additions & 0 deletions install_gpi_batocera.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
echo "Downloading install script .... for BATOCERA"
sleep 2
wget -q -O - https://raw.githubusercontent.com/crcerror/retroflag-picase/master/gpi/batocera_install.sh | bash
4 changes: 4 additions & 0 deletions install_recalbox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
echo "Downloading install script .... for RECALBOX"
sleep 2
wget -q -O - https://raw.githubusercontent.com/crcerror/retroflag-picase/master/other_os/recalbox_install.sh | bash
Loading