added button press service

This commit is contained in:
nagumii 2024-11-18 12:10:12 +02:00
parent 92d112b10e
commit 1dabf61ac2
3 changed files with 29 additions and 0 deletions

11
scripts/button.service Normal file
View file

@ -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

10
scripts/buttonservice.sh Normal file
View file

@ -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

View file

@ -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"