Created
October 17, 2021 21:00
-
-
Save jeevcat/5c67c9a24f4f59ac2073392d91687829 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "TV event detected..." >> /home/sam/tv/tv.log | |
pidof -o %PPID -x $0 >/dev/null && echo "Script already running" && exit 1 | |
if test $(find "/tmp/kodi-started" -mmin 0.1); then | |
echo "Another TV event happened less than 6 seconds ago. Ignoring." >> /home/sam/tv/tv.log | |
exit | |
fi | |
echo "Stopping kodi" >> /home/sam/tv/tv.log | |
systemctl stop kodi-x11 | |
sleep 2 | |
TV_ON=$(cat /sys/class/drm/card0-DP-1/status) | |
echo "TV state changed: $TV_ON" >> /home/sam/tv/tv.log | |
if [ "$TV_ON" == "connected" ]; then | |
echo "Starting kodi" >> /home/sam/tv/tv.log | |
touch /tmp/kodi-started | |
systemctl start kodi-x11 | |
else | |
echo "Kodi already stopped" >> /home/sam/tv/tv.log | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment