diff --git a/scripts/button.service b/scripts/button.service new file mode 100644 index 0000000..4f91a0c --- /dev/null +++ b/scripts/button.service @@ -0,0 +1,11 @@ +[Unit] +Description=Button Reboot Service +After=multi-user.target + +[Service] +ExecStart=/usr/local/bin/buttonservice.sh +Restart=always +User=femto + +[Install] +WantedBy=multi-user.target diff --git a/scripts/buttonservice.sh b/scripts/buttonservice.sh new file mode 100644 index 0000000..d0d5d81 --- /dev/null +++ b/scripts/buttonservice.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +logger "$(date): Listening for button press on $DEVICE..." + +evtest --grab /dev/input/event0 | while read line; do + if echo $line | grep -q "EV_KEY.*value 1"; then + logger "Button pressed, triggering reboot..." + sudo reboot + fi +done diff --git a/scripts/luckfox-install.sh b/scripts/luckfox-install.sh index 55058c0..1767b78 100644 --- a/scripts/luckfox-install.sh +++ b/scripts/luckfox-install.sh @@ -12,6 +12,14 @@ sudo mount -t tmpfs tmpfs /run -o remount,size=32M,nosuid,noexec,relatime,mode=7 sudo sh -c 'echo "tmpfs /run tmpfs size=32M,nosuid,noexec,relatime,mode=755 0 0" >> /etc/fstab' #Embiggen tmpfs - for future boots. echo "*** $(date "+%H:%M:%S %Z"): Enlarged tmpfs ***\e[0m\n" +sudo chmod +x buttonservice.sh +sudo mv buttonservice.sh /usr/local/bin +sudo mv button.service /etc/systemd/system +sudo usermod -aG input $USER +sudo systemctl daemon-reload +sudo systemctl enable button.service +echo "*** $(date "+%H:%M:%S %Z"): Added reboot on BOOT button press ***\e[0m\n" + sudo timedatectl set-timezone UTC #Set timezone to UTC. date -d "$(wget --method=HEAD -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f4-10)" #Set time/date. echo "*** $(date "+%H:%M:%S %Z") Changed timezone to UTC and got network time ***\e[0m\n"