From 290e73f39b440d185b023837d6dfb1cfc1250c56 Mon Sep 17 00:00:00 2001 From: insalada Date: Fri, 7 Dec 2018 12:38:11 +0100 Subject: [PATCH 1/2] first commit --- libreelec_SafeShutdown.py | 45 ++++++++++++++++++++++++++++ libreelec_install.sh | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 libreelec_SafeShutdown.py create mode 100644 libreelec_install.sh diff --git a/libreelec_SafeShutdown.py b/libreelec_SafeShutdown.py new file mode 100644 index 0000000..123fc92 --- /dev/null +++ b/libreelec_SafeShutdown.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +import sys + +# Point out to the library location +sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib/') +from gpiozero import Button, LED +import os +from signal import pause + +# GPIO Settings +powerPin = 3 +resetPin = 2 +ledPin = 14 +powerenPin = 4 +hold = 1 + +# Main LED on +led = LED(ledPin) +led.on() + +# Power LED on +powerLED = LED(powerenPin) +powerLED.on() + +# Functions that handle button events +def pressed(): + led.blink(.2,.2) + os.system("systemctl stop kodi && sleep 5s && shutdown -h now") +def released(): + led.on() +def reboot(): + os.system("systemctl stop kodi && sleep 5s && reboot") + +# Define buttons +powerButton = Button(powerPin, hold_time=hold) +rebootButton = Button(resetPin) + +# Map actions +rebootButton.when_pressed = reboot +powerButton.when_pressed = pressed +powerButton.when_released = released + +# Keep waiting for a button signal +pause() + diff --git a/libreelec_install.sh b/libreelec_install.sh new file mode 100644 index 0000000..5c0cb00 --- /dev/null +++ b/libreelec_install.sh @@ -0,0 +1,63 @@ +#!/bin/bash + + +#Step 1) remount /flash as writtable------------------------ +mount -o remount,rw /flash +echo "Remounted /flash as writtable" + +#Step 2) enable UART---------------------------------------- +cd /flash/ +File=config.txt +if grep -q "enable_uart=1" "$File"; + then + echo "UART already enabled. Doing nothing." + else + echo "enable_uart=1" >> $File + echo "UART enabled." +fi + +#Step 3) Download & rp-tools (includes gpiozero)------------ +echo "Downloading rpi-tools..." +cd /storage/.kodi/addons/ +wget http://addons.libreelec.tv/8.2/RPi2/arm/virtual.rpi-tools/virtual.rpi-tools-8.2.104.zip + +#Step 4) Install-------------------------------------------- +echo "Installing rpi-tools..." +unzip virtual.rpi-tools-8.2.104.zip +rm virtual.rpi-tools-8.2.104.zip +chmod +x /storage/.kodi/addons/virtual.rpi-tools/bin/* + +#Step 5) Download Python script----------------------------- +echo "Downloading python script..." +cd /flash/ +script=libreelec_SafeShutdown.py + +if [ -e $script ]; + then + echo "Script libreelec_SafeShutdown.py already exists. Doing nothing." + else + wget "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/libreelec_SafeShutdown.py" +fi +#----------------------------------------------------------- + +#Step 6) Enable Python script to run on start up------------ +echo "Enabling autostart..." +cd /storage/.config/ +echo "python /flash/libreelec_SafeShutdown.py &" >> autostart.sh +echo "Added to autostart" +#----------------------------------------------------------- + +#Step 7) Reboot to apply changes---------------------------- +echo "RetroFlag Pi Case installation done. Will now reboot after 3 seconds." +sleep 3 +sudo reboot +#----------------------------------------------------------- + + + + + + + + + From 7fc9a75ad7443aecae55c4fb08d6dea35dad6367 Mon Sep 17 00:00:00 2001 From: insalada Date: Fri, 7 Dec 2018 13:23:41 +0100 Subject: [PATCH 2/2] Updated README file --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index fdf089e..0687567 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,22 @@ Example for RecalBox: 5. 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 + +-------------------- + +Example for Kodi (LibreElec): + +**Method A (via ssh):** +1. Get your raspberry IP: Settings > Sytem Information > Network +2. Connect via ssh from your computer: `ssh root@`. Default password is `libreelec` +3. Copy&Paste the command below: + +`wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/libreelec_install.sh" | bash` + +**Method B (directly to your raspberry)** +1. Make sure internet and keyboard are connected. +2. Press CONTROL+ALT+F3 to enter the terminal. +3. User:root Password:libreelec +4. In the terminal, type the one-line command below(Case sensitive): + +`wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/libreelec_install.sh" | bash`