[HowTo] Install Safe Shutdown Script for RetroFlag Cases

RetroFlag cases for the Raspberry can commonly be found on Amazon, have classic gaming console design, and have hardware buttons for both powering off and restarting. RetroFlag has its own official script on GitHub to get the hardware buttons functioning, the problem is this script is geared towards RetroPie and do not work on OSMC.

After hours of looking at various different methods and scripts to get the buttons to work, I came across one that is using systemd instead of rc.local and it was pretty simple to modify to get OSMC supported.

Tested With

  • Device: Raspberry Pi 3 B+
    OSMC Version: 2019.4-1
    RetroFlag Case: SUPERPi CASE-U
    Fan GPIO Pins: pin 1 (3.3v)/pin 9 (Ground)

Supported RetroFlag Cases

Fan Installation

Installing a fan is optional, though the RetroFlag cases do have a spot inside for one to be installed. Some resellers of the cases include a 30mmx30mm 5V fan. The pre-installed PCB inside the case does have a dedicated fan header, I did not use this for MY setup.

For the fan installation instructions I followed Setting up Your Retroflag NESPi Case with a Heatsink and Cooling Fan. The only thing I did differently was I installed my fan to pin 1 (3.3v) and pin 9 (Ground) to minimize noise.

NOTE: Safe Shutdown script successfully stops fan from running on shutdown with my fan setup. I personally have not tested other fan setups.

Instructions

  1. Connect to Raspberry Pi via SSH as osmc user.

    ssh osmc@<IP ADDRESS>
    
  2. Install the dependencies:

    sudo apt-get update
    sudo apt-get install python3 python3-dev python3-setuptools python3-pip gcc 
    sudo pip3 install wheel
    sudo pip3 install rpi.gpio
    
  3. Download ZIP from repository, and extract the contents:

    wget https://gitlab.com/syst3mfailur3/retroflag-picase/-/archive/master/retroflag-picase-master.zip
    unzip retroflag-picase-master.zip
    
  4. Enter into newly extracted directory and run the install script:

    cd retroflag-picase-master
    sudo sh install.sh osmc
    
  5. When prompted, enter Y to reboot.

NOTE: Currently this the scripts files are from my fork of the original repo, will update to main repo if/when my pull request is accepted.

Credits

1 Like

sorry for late replies to mine but great job!!! love this community and the tinkerers!

1 Like

I tried your script and it kinda worked for me. Problem was it didn’t seem to turn off my fan and I saw on ur GitHub issue that you didn’t have one to test with. This script did turn off the fan once I made the changes to remove emulationstation stuff.

Added bonus it uses systemd like yours and not rc.local. Problem is now I want to see if I can check for emulationstation and kill it if it’s present. Down the rabbit hole I go.

1 Like

Here’s another solution I just never posted it here :slight_smile: This script also shuts down a fan if you have one.

https://github.com/Denisuu/OSMC_NesPi-SuperPi_Safe-Shutdown

1 Like

Just to thank you all for your efforts,
I tried your solution denisuu1, it works like a charm, it completly shutdown power which is great if you have usb powered device connected.
(Nespicase+ , OSMC, raspberry PI3b+)

1 Like

Adding a solution for 2023 (and beyond I hope) installers tumbling upon this thread:
OSMC lock the /boot/config.txt file, GPIO overlays must be added to /boot/config-user.txt
I’ve edited the installation script from crcerror to make it work on a fresh OSMC install:

Hope it’ll help others.