From c4882220f936d3bb03e01aafc4e087915c195d1c Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Sat, 17 Apr 2021 16:28:03 -0300 Subject: [PATCH 01/13] Install scripts for Ubuntu --- README.md | 12 +++++- ubuntu_SafeShutdown.py | 83 ++++++++++++++++++++++++++++++++++++ ubuntu_install.sh | 62 +++++++++++++++++++++++++++ ubuntu_safe-shutdown.service | 11 +++++ 4 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 ubuntu_SafeShutdown.py create mode 100644 ubuntu_install.sh create mode 100644 ubuntu_safe-shutdown.service diff --git a/README.md b/README.md index 0e6125d..92637f4 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/r -# retroflag-picase (nespi+, superpi, megapi,nespi4 case) +# retroflag-picase (nespi+, superpi, megapi, nespi4 case) RetroFlag Pi-Case Safe Shutdown Turn switch "SAFE SHUTDOWN" to ON. @@ -61,5 +61,15 @@ wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/b -------------------- +Example for Ubuntu: +1. Make sure internet connected. +2. Make sure keyboard connected. +3. Enter terminal. +4. In the terminal, type the one-line command below(Case sensitive): + +wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/ubuntu_install.sh" | bash + +-------------------- + Example for lakkatv: https://github.com/marcelonovaes/lakka_nespi_power diff --git a/ubuntu_SafeShutdown.py b/ubuntu_SafeShutdown.py new file mode 100644 index 0000000..905f45b --- /dev/null +++ b/ubuntu_SafeShutdown.py @@ -0,0 +1,83 @@ +import RPi.GPIO as GPIO +import os +import time +from multiprocessing import Process + +#initialize pins +powerPin = 3 #pin 5 +ledPin = 14 #TXD +resetPin = 2 #pin 13 +powerenPin = 4 #pin 5 + +#initialize GPIO settings +def init(): + GPIO.setwarnings(False) + GPIO.setmode(GPIO.BCM) + GPIO.setup(powerPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + GPIO.setup(resetPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + GPIO.setup(ledPin, GPIO.OUT) + GPIO.output(ledPin, GPIO.HIGH) + GPIO.setup(powerenPin, GPIO.OUT) + GPIO.output(powerenPin, GPIO.HIGH) + +#waits for user to hold button up to 1 second before issuing poweroff command +def poweroff(): + while True: + #self.assertEqual(GPIO.input(powerPin), GPIO.LOW) + GPIO.wait_for_edge(powerPin, GPIO.FALLING) + os.system("sleep 1s") + os.system("poweroff") + +#blinks the LED to signal button being pushed +def powerLedBlink(): + while True: + GPIO.output(ledPin, GPIO.HIGH) + #self.assertEqual(GPIO.input(powerPin), GPIO.LOW) + GPIO.wait_for_edge(powerPin, GPIO.FALLING) + start = time.time() + while GPIO.input(powerPin) == GPIO.LOW: + GPIO.output(ledPin, GPIO.LOW) + time.sleep(0.2) + GPIO.output(ledPin, GPIO.HIGH) + time.sleep(0.2) + +def resetLedBlink(): + while True: + GPIO.output(ledPin, GPIO.HIGH) + #self.assertEqual(GPIO.input(powerPin), GPIO.LOW) + GPIO.wait_for_edge(resetPin, GPIO.FALLING) + start = time.time() + while GPIO.input(resetPin) == GPIO.LOW: + GPIO.output(ledPin, GPIO.LOW) + time.sleep(0.2) + GPIO.output(ledPin, GPIO.HIGH) + time.sleep(0.2) + +#resets the pi +def reset(): + while True: + #self.assertEqual(GPIO.input(resetPin), GPIO.LOW) + GPIO.wait_for_edge(resetPin, GPIO.FALLING) + os.system("sleep 1s") + os.system("reboot") + + +if __name__ == "__main__": + #initialize GPIO settings + init() + #create a multiprocessing.Process instance for each function to enable parallelism + powerProcess = Process(target = poweroff) + powerProcess.start() + resetProcess = Process(target = reset) + resetProcess.start() + powerLedProcess = Process(target = powerLedBlink) + powerLedProcess.start() + resetLedProcess = Process(target = resetLedBlink) + resetLedProcess.start() + + powerProcess.join() + resetProcess.join() + powerLedProcess.join() + resetLedProcess.join() + + GPIO.cleanup() diff --git a/ubuntu_install.sh b/ubuntu_install.sh new file mode 100644 index 0000000..94face2 --- /dev/null +++ b/ubuntu_install.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +SourcePath=https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master + +#Check if root-------------------------------------- +if [[ $EUID -ne 0 ]]; then + echo "Please execute script as root." + exit 1 +fi +#----------------------------------------------------------- + +#RetroFlag pw io ;2:in ;3:in ;4:in ;14:out 1---------------------------------------- +File=/boot/firmware/config.txt +wget -O "/boot/overlays/RetroFlag_pw_io.dtbo" "$SourcePath/RetroFlag_pw_io.dtbo" +if grep -q "RetroFlag_pw_io" "$File"; + then + sed -i '/RetroFlag_pw_io/c dtoverlay=RetroFlag_pw_io.dtbo' $File + echo "PW IO fix." + else + echo "dtoverlay=RetroFlag_pw_io.dtbo" >> $File + echo "dtoverlay=gpio-poweroff,gpiopin=4,active_low=1,input=1" >> $File + echo "PW IO enabled." +fi +if grep -q "enable_uart" "$File"; + then + sed -i '/enable_uart/c enable_uart=1' $File + echo "UART fix." + else + echo "enable_uart=1" >> $File + echo "UART enabled." +fi + +#----------------------------------------------------------- + +#Download Python script----------------------------- +mkdir "/opt/RetroFlag" +script=/opt/RetroFlag/SafeShutdown.py +wget -O $script "$SourcePath/ubuntu_SafeShutdown.py" + +#Enable Python script to run on start up------------ +service=/lib/systemd/system/safe-shutdown.service +wget -O $service "$SourcePath/ubuntu_safe-shutdown.service" + +systemctl enable safe-shutdown +echo "Added service '$service' to system startup." + +#----------------------------------------------------------- + +#Reboot to apply changes---------------------------- +echo "RetroFlag Pi Case installation done. Will now reboot after 3 seconds." +sleep 3 +sudo reboot +#----------------------------------------------------------- + + + + + + + + + diff --git a/ubuntu_safe-shutdown.service b/ubuntu_safe-shutdown.service new file mode 100644 index 0000000..83519da --- /dev/null +++ b/ubuntu_safe-shutdown.service @@ -0,0 +1,11 @@ +[Unit] +Description=Nespi4 Case Safe Shutdown + +[Service] +Type=idle +ExecStart=/usr/bin/python3 /opt/RetroFlag/SafeShutdown.py +StandardOutput=null + +[Install] +WantedBy=multi-user.target +Alias=safe-shutdown.service From d515fbbc84e60735d5d54c4200c50bc9909c9424 Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Sat, 17 Apr 2021 16:54:39 -0300 Subject: [PATCH 02/13] Working --- README.md | 9 +++++++-- ubuntu_install.sh | 14 +++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 92637f4..c7fe15c 100644 --- a/README.md +++ b/README.md @@ -59,15 +59,20 @@ Example for batocera: wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/batocera_install.sh" | bash +# retroflag-nespi4 +RetroFlag Nespi4 Case Safe Shutdown + +Turn switch "SAFE SHUTDOWN" to ON. + -------------------- -Example for Ubuntu: +Example for Ubuntu 20.10+: 1. Make sure internet connected. 2. Make sure keyboard connected. 3. Enter terminal. 4. In the terminal, type the one-line command below(Case sensitive): -wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/ubuntu_install.sh" | bash +wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/ubuntu_install.sh" | sudo bash -------------------- diff --git a/ubuntu_install.sh b/ubuntu_install.sh index 94face2..b1f4974 100644 --- a/ubuntu_install.sh +++ b/ubuntu_install.sh @@ -1,6 +1,7 @@ #!/bin/bash -SourcePath=https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master +[ -z $SourcePath ] && SourcePath=https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master + #Check if root-------------------------------------- if [[ $EUID -ne 0 ]]; then @@ -11,7 +12,7 @@ fi #RetroFlag pw io ;2:in ;3:in ;4:in ;14:out 1---------------------------------------- File=/boot/firmware/config.txt -wget -O "/boot/overlays/RetroFlag_pw_io.dtbo" "$SourcePath/RetroFlag_pw_io.dtbo" +wget -O "/boot/firmware/overlays/RetroFlag_pw_io.dtbo" "$SourcePath/RetroFlag_pw_io.dtbo" if grep -q "RetroFlag_pw_io" "$File"; then sed -i '/RetroFlag_pw_io/c dtoverlay=RetroFlag_pw_io.dtbo' $File @@ -51,12 +52,3 @@ echo "RetroFlag Pi Case installation done. Will now reboot after 3 seconds." sleep 3 sudo reboot #----------------------------------------------------------- - - - - - - - - - From 8bc5aa3533e78471a9271b24c28d7c91d322af88 Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Sat, 17 Apr 2021 17:07:37 -0300 Subject: [PATCH 03/13] Fix command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c7fe15c..843c34a 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Example for Ubuntu 20.10+: 3. Enter terminal. 4. In the terminal, type the one-line command below(Case sensitive): -wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/ubuntu_install.sh" | sudo bash +echo "wget -O - "https://raw.githubusercontent.com/rfocosi/retroflag-picase/master/ubuntu_install.sh" | SourcePath="https://raw.githubusercontent.com/rfocosi/retroflag-picase/master" bash" | sudo bash -------------------- From b06de3eaa82544d7f6e5c6f5fc7d406f8c241851 Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Sat, 17 Apr 2021 18:00:09 -0300 Subject: [PATCH 04/13] Nespi4 Ubuntu scripts --- README.md | 4 ++-- ubuntu_install.sh | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 843c34a..0ad2968 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Example for batocera: wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/batocera_install.sh" | bash -# retroflag-nespi4 +# retroflag-nespi4 Ubuntu RetroFlag Nespi4 Case Safe Shutdown Turn switch "SAFE SHUTDOWN" to ON. @@ -72,7 +72,7 @@ Example for Ubuntu 20.10+: 3. Enter terminal. 4. In the terminal, type the one-line command below(Case sensitive): -echo "wget -O - "https://raw.githubusercontent.com/rfocosi/retroflag-picase/master/ubuntu_install.sh" | SourcePath="https://raw.githubusercontent.com/rfocosi/retroflag-picase/master" bash" | sudo bash +echo "wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/ubuntu_install.sh" | bash" | sudo bash -------------------- diff --git a/ubuntu_install.sh b/ubuntu_install.sh index b1f4974..f231f18 100644 --- a/ubuntu_install.sh +++ b/ubuntu_install.sh @@ -1,11 +1,11 @@ #!/bin/bash -[ -z $SourcePath ] && SourcePath=https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master +SourcePath=https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master #Check if root-------------------------------------- if [[ $EUID -ne 0 ]]; then - echo "Please execute script as root." + echo "Please execute script as root." exit 1 fi #----------------------------------------------------------- @@ -15,7 +15,7 @@ File=/boot/firmware/config.txt wget -O "/boot/firmware/overlays/RetroFlag_pw_io.dtbo" "$SourcePath/RetroFlag_pw_io.dtbo" if grep -q "RetroFlag_pw_io" "$File"; then - sed -i '/RetroFlag_pw_io/c dtoverlay=RetroFlag_pw_io.dtbo' $File + sed -i '/RetroFlag_pw_io/c dtoverlay=RetroFlag_pw_io.dtbo' $File echo "PW IO fix." else echo "dtoverlay=RetroFlag_pw_io.dtbo" >> $File @@ -24,7 +24,7 @@ if grep -q "RetroFlag_pw_io" "$File"; fi if grep -q "enable_uart" "$File"; then - sed -i '/enable_uart/c enable_uart=1' $File + sed -i '/enable_uart/c enable_uart=1' $File echo "UART fix." else echo "enable_uart=1" >> $File From 2c05239b70cae40f850b8af9ff48e73a22cab72c Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Sun, 24 Apr 2022 19:55:26 -0300 Subject: [PATCH 05/13] Add PYTHON_EXEC variable --- ubuntu_safe-shutdown.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubuntu_safe-shutdown.service b/ubuntu_safe-shutdown.service index 83519da..010296a 100644 --- a/ubuntu_safe-shutdown.service +++ b/ubuntu_safe-shutdown.service @@ -3,7 +3,7 @@ Description=Nespi4 Case Safe Shutdown [Service] Type=idle -ExecStart=/usr/bin/python3 /opt/RetroFlag/SafeShutdown.py +ExecStart=PYTHON_EXEC /opt/RetroFlag/SafeShutdown.py StandardOutput=null [Install] From 7095ca7f634a84bde857e6d0cb198ea5e4eef955 Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Sun, 24 Apr 2022 20:19:21 -0300 Subject: [PATCH 06/13] Add more binary checks to ubuntu_install --- ubuntu_install.sh | 49 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/ubuntu_install.sh b/ubuntu_install.sh index b1f4974..f8aca96 100644 --- a/ubuntu_install.sh +++ b/ubuntu_install.sh @@ -1,18 +1,50 @@ #!/bin/bash +#DEV_ROOT= + +CURL_EXEC=$( which curl ) +PYTHON_EXEC=$( which python | which python3 ) +WGET_EXEC=$( which wget ) + [ -z $SourcePath ] && SourcePath=https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master #Check if root-------------------------------------- if [[ $EUID -ne 0 ]]; then + echo echo "Please execute script as root." exit 1 fi -#----------------------------------------------------------- +#--------------------------------------------------- + +if [[ -z "$WGET_EXEC" ]]; then + echo + echo "Requires 'wget'. Please install and try again." + exit 1 +fi + +if [[ -z "$CURL_EXEC" ]]; then + echo + echo "Requires 'curl'. Please install and try again." + exit 1 +fi + +if [[ -z "$PYTHON_EXEC" || ! "$( $PYTHON_EXEC -V )" = "Python 3"* ]]; then + echo + echo "Requires 'python3'. Please install and try again." + exit 1 +fi + +if [[ -z "$( python3 -c "import RPi.GPIO as GPIO; print(GPIO.VERSION)" )" ]]; then + echo + echo "Library 'python3-rpi.gpio' not found. Please install and try again." + exit 1 +fi #RetroFlag pw io ;2:in ;3:in ;4:in ;14:out 1---------------------------------------- -File=/boot/firmware/config.txt -wget -O "/boot/firmware/overlays/RetroFlag_pw_io.dtbo" "$SourcePath/RetroFlag_pw_io.dtbo" +[[ ! -z "$DEV_ROOT" ]] && mkdir -p $DEV_ROOT/boot/firmware/overlays +File=$DEV_ROOT/boot/firmware/config.txt +$WGET_EXEC -q -O "$DEV_ROOT/boot/firmware/overlays/RetroFlag_pw_io.dtbo" "$SourcePath/RetroFlag_pw_io.dtbo" if grep -q "RetroFlag_pw_io" "$File"; then sed -i '/RetroFlag_pw_io/c dtoverlay=RetroFlag_pw_io.dtbo' $File @@ -34,13 +66,14 @@ fi #----------------------------------------------------------- #Download Python script----------------------------- -mkdir "/opt/RetroFlag" -script=/opt/RetroFlag/SafeShutdown.py -wget -O $script "$SourcePath/ubuntu_SafeShutdown.py" +mkdir -p "$DEV_ROOT/opt/RetroFlag" +script=$DEV_ROOT/opt/RetroFlag/SafeShutdown.py +$WGET_EXEC -q -O $script "$SourcePath/ubuntu_SafeShutdown.py" #Enable Python script to run on start up------------ -service=/lib/systemd/system/safe-shutdown.service -wget -O $service "$SourcePath/ubuntu_safe-shutdown.service" +[[ ! -z "$DEV_ROOT" ]] && mkdir -p $DEV_ROOT/lib/systemd/system/ +service=$DEV_ROOT/lib/systemd/system/safe-shutdown.service +curl -s "$SourcePath/ubuntu_safe-shutdown.service" | awk '{gsub(/PYTHON_EXEC/,"'$PYTHON_EXEC'")}1' > $service systemctl enable safe-shutdown echo "Added service '$service' to system startup." From 135c6f9af78cf0ccd83e90a0531caaa27d02f04e Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Sun, 24 Apr 2022 20:35:31 -0300 Subject: [PATCH 07/13] Merge upstream --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ad2968..0fbb788 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ Example for Ubuntu 20.10+: echo "wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/ubuntu_install.sh" | bash" | sudo bash --------------------- +------------------- Example for lakkatv: https://github.com/marcelonovaes/lakka_nespi_power From 4240e13a6cf9518c1850701dcd0c1f75934215ce Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Sun, 24 Apr 2022 20:36:32 -0300 Subject: [PATCH 08/13] Merge upstream --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fbb788..0ad2968 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ Example for Ubuntu 20.10+: echo "wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/ubuntu_install.sh" | bash" | sudo bash -------------------- +-------------------- Example for lakkatv: https://github.com/marcelonovaes/lakka_nespi_power From ec63e70d5ca55bbc362f283c9ac73252f140e827 Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Tue, 6 Dec 2022 19:43:20 -0300 Subject: [PATCH 09/13] Scripts for Ubuntu 22 --- RetroFlag_Ubuntu22.dtbo | Bin 0 -> 444 bytes Retroflag_Ubuntu22.README | 14 +++++++ Retroflag_Ubuntu22.dts | 18 ++++++++ ubuntu22_SafeShutdown.py | 34 +++++++++++++++ ubuntu22_install.sh | 85 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 151 insertions(+) create mode 100644 RetroFlag_Ubuntu22.dtbo create mode 100644 Retroflag_Ubuntu22.README create mode 100644 Retroflag_Ubuntu22.dts create mode 100644 ubuntu22_SafeShutdown.py create mode 100644 ubuntu22_install.sh diff --git a/RetroFlag_Ubuntu22.dtbo b/RetroFlag_Ubuntu22.dtbo new file mode 100644 index 0000000000000000000000000000000000000000..41fffba5cec9193e23fc691331207ec5ce2a6559 GIT binary patch literal 444 zcmb`DF%H5o3`Jd#Kt&+IzzJ9wSdcm}atyYpv?*9BNmLvVx8Oh=f{Snkgq?tZg^5bP z_J4K1m0Sn+8$faafCbkx*C}hn8nWb>F<-^@>zzDZa==pC!ZtdB#G%=%Y%NZDRajHu zCVUjXEOnLpngq02eQEN7@SxQeH(Rm7d#u#?x>lt<8ljP=T*qkQAAv^R;eLX~`H&3I zVjuRoEKEseS7xlI*U+y$GCTg*^3I!wz<=aP=BH9;>%2ia0qJJPha|KH_LMi|o#ILw KDsT9*7(W0G97@^% literal 0 HcmV?d00001 diff --git a/Retroflag_Ubuntu22.README b/Retroflag_Ubuntu22.README new file mode 100644 index 0000000..28dfc24 --- /dev/null +++ b/Retroflag_Ubuntu22.README @@ -0,0 +1,14 @@ +Firmware overlay for Ubuntu 22+ +=============================== + +This overlay will turn on GPIO 4 and 14 at startup. + +To compile, execute the command: +dtc -I dts -O dtb -o RetroFlag_Ubuntu22.dtbo RetroFlag_Ubuntu22.dts + +After: +- Copy RetroFlag_Ubuntu22.dtbo to /boot/firmware/overlays +- Add this line to the end of /boot/firmware/config.txt: +dtoverlay=RetroFlag_Ubuntu22.dtbo + + diff --git a/Retroflag_Ubuntu22.dts b/Retroflag_Ubuntu22.dts new file mode 100644 index 0000000..dfc063d --- /dev/null +++ b/Retroflag_Ubuntu22.dts @@ -0,0 +1,18 @@ +/dts-v1/; + +/ { + videocore { + pins_4b { // Pi4 Model B + pin_config { + pin@default { + polarity = "active_high"; + termination = "pull_down"; + startup_state = "inactive"; + function = "input"; + }; // pin + pin@p4 { function = "output"; termination = "pull_down"; startup_state = "active"; }; // ON + pin@p14 { function = "output"; termination = "pull_down"; startup_state = "active"; }; // LED + }; // pin_config + }; + }; +}; diff --git a/ubuntu22_SafeShutdown.py b/ubuntu22_SafeShutdown.py new file mode 100644 index 0000000..57b2fda --- /dev/null +++ b/ubuntu22_SafeShutdown.py @@ -0,0 +1,34 @@ +from gpiozero import Button, LED +import os +from signal import pause +import subprocess + +#initialize pins +powerBtnPin = 3 +resetBtnPin = 2 +ledPin = 14 +powerPin = 4 + +led = LED(ledPin) +led.on() + +power = LED(powerPin) +power.on() + +#functions that handle button events +def poweroff(): + led.blink(.2,.2) + print("sudo shutdown -h now") + #os.system("sudo shutdown -h now") + +def reboot(): + led.blink(.2,.2) + print("sudo reboot") + +powerBtn = Button(powerBtnPin) +rebootBtn = Button(resetBtnPin) + +powerBtn.when_pressed = poweroff +rebootBtn.when_pressed = reboot + +pause() diff --git a/ubuntu22_install.sh b/ubuntu22_install.sh new file mode 100644 index 0000000..2b58809 --- /dev/null +++ b/ubuntu22_install.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +#DEV_ROOT= + +CURL_EXEC=$( which curl ) +PYTHON_EXEC=$( which python | which python3 ) +WGET_EXEC=$( which wget ) + +[ -z $SourcePath ] && SourcePath=https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master + +#Check if root-------------------------------------- +if [[ $EUID -ne 0 ]]; then + echo + echo "Please execute script as root." + exit 1 +fi +#--------------------------------------------------- + +if [[ -z "$WGET_EXEC" ]]; then + echo + echo "Requires 'wget'. Please install and try again." + exit 1 +fi + +if [[ -z "$CURL_EXEC" ]]; then + echo + echo "Requires 'curl'. Please install and try again." + exit 1 +fi + +if [[ -z "$PYTHON_EXEC" || ! "$( $PYTHON_EXEC -V )" = "Python 3"* ]]; then + echo + echo "Requires 'python3'. Please install and try again." + exit 1 +fi + +if [[ -z "$( python3 -c "import sys; import gpiozero; print('Found') if 'gpiozero' in sys.modules else print('')" )" ]]; then + echo + echo "Library 'python3-gpiozero' not found. Please install and try again." + exit 1 +fi + +#RetroFlag pw io ;2:in ;3:in ;4:in ;14:out 1---------------------------------------- +[[ ! -z "$DEV_ROOT" ]] && mkdir -p $DEV_ROOT/boot/firmware/overlays +File=$DEV_ROOT/boot/firmware/config.txt +$WGET_EXEC -q -O "$DEV_ROOT/boot/firmware/overlays/RetroFlag_Ubuntu22.dtbo" "$SourcePath/RetroFlag_Ubuntu22.dtbo" +if grep -q "RetroFlag_Ubuntu22" "$File"; + then + sed -i '/RetroFlag_Ubuntu22/c dtoverlay=RetroFlag_Ubuntu22.dtbo' $File + echo "PW IO fix." + else + echo "dtoverlay=RetroFlag_Ubuntu22.dtbo" >> $File + echo "PW IO enabled." +fi +if grep -q "enable_uart" "$File"; + then + sed -i '/enable_uart/c enable_uart=1' $File + echo "UART fix." + else + echo "enable_uart=1" >> $File + echo "UART enabled." +fi + +#----------------------------------------------------------- + +#Download Python script----------------------------- +mkdir -p "$DEV_ROOT/opt/RetroFlag" +script=$DEV_ROOT/opt/RetroFlag/SafeShutdown.py +$WGET_EXEC -q -O $script "$SourcePath/ubuntu22_SafeShutdown.py" + +#Enable Python script to run on start up------------ +[[ ! -z "$DEV_ROOT" ]] && mkdir -p $DEV_ROOT/lib/systemd/system/ +service=$DEV_ROOT/lib/systemd/system/safe-shutdown.service +curl -s "$SourcePath/ubuntu_safe-shutdown.service" | awk '{gsub(/PYTHON_EXEC/,"'$PYTHON_EXEC'")}1' > $service + +systemctl enable safe-shutdown +echo "Added service '$service' to system startup." + +#----------------------------------------------------------- + +#Reboot to apply changes---------------------------- +echo "RetroFlag Pi Case installation done. Will now reboot after 3 seconds." +sleep 3 +sudo reboot +#----------------------------------------------------------- From f97504b1f703da128743915cbebea9acc84ac237 Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Tue, 6 Dec 2022 20:11:04 -0300 Subject: [PATCH 10/13] Add os.system --- ubuntu22_SafeShutdown.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ubuntu22_SafeShutdown.py b/ubuntu22_SafeShutdown.py index 57b2fda..2694708 100644 --- a/ubuntu22_SafeShutdown.py +++ b/ubuntu22_SafeShutdown.py @@ -18,12 +18,11 @@ #functions that handle button events def poweroff(): led.blink(.2,.2) - print("sudo shutdown -h now") - #os.system("sudo shutdown -h now") + os.system("shutdown -h now") def reboot(): led.blink(.2,.2) - print("sudo reboot") + os.system("reboot") powerBtn = Button(powerBtnPin) rebootBtn = Button(resetBtnPin) From 5620ec9a60e630dc281b512f7efa654e545eff14 Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Tue, 6 Dec 2022 20:37:14 -0300 Subject: [PATCH 11/13] Change pin termination --- ...Ubuntu22.README => RetroFlag_Ubuntu22.README | 0 RetroFlag_Ubuntu22.dtbo | Bin 444 -> 436 bytes ...oflag_Ubuntu22.dts => RetroFlag_Ubuntu22.dts | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename Retroflag_Ubuntu22.README => RetroFlag_Ubuntu22.README (100%) rename Retroflag_Ubuntu22.dts => RetroFlag_Ubuntu22.dts (72%) diff --git a/Retroflag_Ubuntu22.README b/RetroFlag_Ubuntu22.README similarity index 100% rename from Retroflag_Ubuntu22.README rename to RetroFlag_Ubuntu22.README diff --git a/RetroFlag_Ubuntu22.dtbo b/RetroFlag_Ubuntu22.dtbo index 41fffba5cec9193e23fc691331207ec5ce2a6559..becc677a8ab31a805b4fe4d15e131f42e2b266a7 100644 GIT binary patch delta 63 zcmdnPyoFid0`I@K3=E807#J8VfON-10ddBFi5j Date: Tue, 6 Dec 2022 22:48:56 -0300 Subject: [PATCH 12/13] Working version --- RetroFlag_Ubuntu22.README | 2 +- RetroFlag_Ubuntu22.dtbo | Bin 436 -> 388 bytes RetroFlag_Ubuntu22.dts | 3 +-- ubuntu22_SafeShutdown.py | 4 ---- ubuntu22_install.sh | 1 + 5 files changed, 3 insertions(+), 7 deletions(-) diff --git a/RetroFlag_Ubuntu22.README b/RetroFlag_Ubuntu22.README index 28dfc24..f4e3f46 100644 --- a/RetroFlag_Ubuntu22.README +++ b/RetroFlag_Ubuntu22.README @@ -1,7 +1,7 @@ Firmware overlay for Ubuntu 22+ =============================== -This overlay will turn on GPIO 4 and 14 at startup. +This overlay will turn on GPIO 4 at startup. To compile, execute the command: dtc -I dts -O dtb -o RetroFlag_Ubuntu22.dtbo RetroFlag_Ubuntu22.dts diff --git a/RetroFlag_Ubuntu22.dtbo b/RetroFlag_Ubuntu22.dtbo index becc677a8ab31a805b4fe4d15e131f42e2b266a7..8ea62872f675d04704b6dfd6c671e184301f5171 100644 GIT binary patch delta 78 zcmdnO+`=qyf%o5A1_s6!1_lNTARRGLK%7xwqQ-3vE}#f!L1|7-d`fJ_^H diff --git a/RetroFlag_Ubuntu22.dts b/RetroFlag_Ubuntu22.dts index 74a6e83..2b1572a 100644 --- a/RetroFlag_Ubuntu22.dts +++ b/RetroFlag_Ubuntu22.dts @@ -10,8 +10,7 @@ startup_state = "inactive"; function = "input"; }; // pin - pin@p4 { function = "output"; termination = "pull_up"; startup_state = "active"; }; // ON - pin@p14 { function = "output"; termination = "pull_up"; startup_state = "active"; }; // LED + pin@p4 { function = "output"; termination = "pull_down"; polarity = "active_low"; startup_state = "active"; }; // ON }; // pin_config }; }; diff --git a/ubuntu22_SafeShutdown.py b/ubuntu22_SafeShutdown.py index 2694708..ca49937 100644 --- a/ubuntu22_SafeShutdown.py +++ b/ubuntu22_SafeShutdown.py @@ -7,14 +7,10 @@ powerBtnPin = 3 resetBtnPin = 2 ledPin = 14 -powerPin = 4 led = LED(ledPin) led.on() -power = LED(powerPin) -power.on() - #functions that handle button events def poweroff(): led.blink(.2,.2) diff --git a/ubuntu22_install.sh b/ubuntu22_install.sh index 2b58809..f8ad3bb 100644 --- a/ubuntu22_install.sh +++ b/ubuntu22_install.sh @@ -50,6 +50,7 @@ if grep -q "RetroFlag_Ubuntu22" "$File"; echo "PW IO fix." else echo "dtoverlay=RetroFlag_Ubuntu22.dtbo" >> $File + echo "dtoverlay=gpio-poweroff,gpiopin=4,active_low=1,input=1" echo "PW IO enabled." fi if grep -q "enable_uart" "$File"; From 59fc640576817ab25f1e3f71dffc114750cf9f70 Mon Sep 17 00:00:00 2001 From: Roberto Focosi Date: Thu, 8 Dec 2022 23:00:04 -0300 Subject: [PATCH 13/13] Change paths and fix ubuntu22_install.sh script --- README.md | 23 +++++++++-------------- ubuntu22_install.sh | 8 ++++---- ubuntu_install.sh | 2 +- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b61f2e8..72dfb78 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ RetroFlag Pi-Case Safe Shutdown ### Turn switch "SAFE SHUTDOWN" to ON. -### Example for RetroPie: +### RetroPie: 1. Make sure internet connected. 2. Make sure keyboard connected. 3. Press F4 enter terminal. @@ -61,8 +61,7 @@ RetroFlag Pi-Case Safe Shutdown wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/install.sh" | sudo bash - -### Example for RecalBox: +### RecalBox: 1. Make sure internet connected. 2. Make sure keyboard connected. 3. Press F4 first. And then press ALT-F2 enter terminal. @@ -72,8 +71,7 @@ wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/i wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/recalbox_install.sh" | bash - -### Example for batocera: +### Batocera: 1. Make sure internet connected. 2. Make sure keyboard connected. 3. Enter terminal. How to enter terminal: https://wiki.batocera.org/access_the_batocera_via_ssh @@ -82,20 +80,17 @@ wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/r wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/batocera_install.sh" | bash -# retroflag-nespi4 Ubuntu -RetroFlag Nespi4 Case Safe Shutdown - -Turn switch "SAFE SHUTDOWN" to ON. - --------------------- - -Example for Ubuntu 20.10+: +### Ubuntu 1. Make sure internet connected. 2. Make sure keyboard connected. 3. Enter terminal. 4. In the terminal, type the one-line command below(Case sensitive): -echo "wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/ubuntu_install.sh" | bash" | sudo bash +Ubuntu 20.10 to 21.10: +wget -O - "https://raw.githubusercontent.com/rfocosi/retroflag-picase/master/ubuntu_install.sh" | sudo bash + +Ubuntu 22.04+: +wget -O - "https://raw.githubusercontent.com/rfocosi/retroflag-picase/master/ubuntu22_install.sh" | sudo bash -------------------- diff --git a/ubuntu22_install.sh b/ubuntu22_install.sh index f8ad3bb..b5d8df5 100644 --- a/ubuntu22_install.sh +++ b/ubuntu22_install.sh @@ -6,7 +6,7 @@ CURL_EXEC=$( which curl ) PYTHON_EXEC=$( which python | which python3 ) WGET_EXEC=$( which wget ) -[ -z $SourcePath ] && SourcePath=https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master +[ -z $SourcePath ] && SourcePath=https://raw.githubusercontent.com/rfocosi/retroflag-picase/master #Check if root-------------------------------------- if [[ $EUID -ne 0 ]]; then @@ -44,13 +44,13 @@ fi [[ ! -z "$DEV_ROOT" ]] && mkdir -p $DEV_ROOT/boot/firmware/overlays File=$DEV_ROOT/boot/firmware/config.txt $WGET_EXEC -q -O "$DEV_ROOT/boot/firmware/overlays/RetroFlag_Ubuntu22.dtbo" "$SourcePath/RetroFlag_Ubuntu22.dtbo" -if grep -q "RetroFlag_Ubuntu22" "$File"; +if grep -q "RetroFlag_" "$File"; then - sed -i '/RetroFlag_Ubuntu22/c dtoverlay=RetroFlag_Ubuntu22.dtbo' $File + sed -i '/RetroFlag_/c dtoverlay=RetroFlag_Ubuntu22.dtbo' $File echo "PW IO fix." else echo "dtoverlay=RetroFlag_Ubuntu22.dtbo" >> $File - echo "dtoverlay=gpio-poweroff,gpiopin=4,active_low=1,input=1" + echo "dtoverlay=gpio-poweroff,gpiopin=4,active_low=1,input=1" >> $File echo "PW IO enabled." fi if grep -q "enable_uart" "$File"; diff --git a/ubuntu_install.sh b/ubuntu_install.sh index 3ed1dc5..86906d9 100644 --- a/ubuntu_install.sh +++ b/ubuntu_install.sh @@ -6,7 +6,7 @@ CURL_EXEC=$( which curl ) PYTHON_EXEC=$( which python | which python3 ) WGET_EXEC=$( which wget ) -[ -z $SourcePath ] && SourcePath=https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master +[ -z $SourcePath ] && SourcePath=https://raw.githubusercontent.com/rfocosi/retroflag-picase/master #Check if root-------------------------------------- if [[ $EUID -ne 0 ]]; then