diff --git a/README.md b/README.md index fdf089e..688bf9c 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,12 @@ 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 Raspbian: +1. Make sure internet connected. +2. Make sure keyboard connected. +3. In the terminal, type the one-line command below(Case sensitive): + +wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/raspbian_install.sh" | sudo bash diff --git a/raspbian_SafeShutdown.py b/raspbian_SafeShutdown.py new file mode 100644 index 0000000..23798a5 --- /dev/null +++ b/raspbian_SafeShutdown.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +from gpiozero import Button, LED +import os +from signal import pause + +powerPin = 3 +resetPin = 2 +ledPin = 14 +powerenPin = 4 +hold = 1 +led = LED(ledPin) +led.on() +power = LED(powerenPin) +power.on() + +#functions that handle button events +def when_pressed(): + led.blink(.2,.2) + os.system("sudo shutdown -h now") +def when_released(): + led.on() +def reboot(): + os.system("sudo reboot") + +btn = Button(powerPin, hold_time=hold) +rebootBtn = Button(resetPin) +rebootBtn.when_pressed = reboot +btn.when_pressed = when_pressed +btn.when_released = when_released +pause() diff --git a/raspbian_install.sh b/raspbian_install.sh new file mode 100644 index 0000000..535acad --- /dev/null +++ b/raspbian_install.sh @@ -0,0 +1,62 @@ +#!/bin/bash + + +#Step 1) Check if root-------------------------------------- +if [[ $EUID -ne 0 ]]; then + echo "Please execute script as root." + exit 1 +fi +#----------------------------------------------------------- + +#Step 2) enable UART---------------------------------------- +cd /boot/ +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) 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 +cd /opt/RetroFlag +script=raspbian_SafeShutdown.py + +if [ -e $script ]; + then + echo "Script raspbian_SafeShutdown.py already exists. Doing nothing." + else + wget "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/raspbian_SafeShutdown.py" +fi +#----------------------------------------------------------- + +#Step 6) Enable Python script to run on start up------------ +cd /etc/ +RC=rc.local + +if grep -q "sudo python3 \/opt\/RetroFlag\/raspbian_SafeShutdown.py \&" "$RC"; + then + echo "File /etc/rc.local already configured. Doing nothing." + else + sed -i -e "s/^exit 0/sudo python3 \/opt\/RetroFlag\/raspbian_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 3 +sudo reboot +#-----------------------------------------------------------