RandomVideo/RandomVideo.sh

55 lines
1.0 KiB
Bash
Raw Normal View History

#!/bin/sh
2020-09-23 15:18:30 +02:00
# SPDX-License-Identifier: Unlicense
cmdjq="$(command -v jq)"
if [ -z "$cmdjq" ]; then
2020-09-24 10:44:28 +02:00
echo "Missing \"jq\"!"
exit 1
fi
2020-09-24 15:39:16 +02:00
configfile="config.json"
2020-09-24 15:34:33 +02:00
folder="$($cmdjq -r ".RandomVideo | .folder" < $configfile)"
player="$($cmdjq -r ".player" < $configfile)"
playerparam="$($cmdjq -r ".playerparam" < $configfile)"
pgrepplayer="$($cmdjq -r ".pgrepplayer" < $configfile)"
2020-09-24 15:34:33 +02:00
swupgpio="$($cmdjq -r ".swupgpio" < $configfile)"
2020-09-19 23:33:19 +02:00
2020-09-23 15:18:30 +02:00
playerfull="$(command -v $player) $playerparam"
swupstat="$($(command -v gpio) read $swupgpio)"
2020-09-19 23:33:19 +02:00
if [ $# -eq 0 ]; then
echo "Parameter fehlt"
exit 1
fi
if [ $# -gt 1 ]; then
echo "Zu viele Parameter"
exit 1
fi
2020-09-23 15:18:30 +02:00
if [ "$swupstat" -eq 1 ]; then
2020-09-19 23:33:19 +02:00
exit 1
fi
if [ "buzzer" != "$1" ] && [ "cron" != "$1" ]; then
echo "Parameter muss \"buzzer\" oder \"cron\" sein"
exit 1
fi
2020-09-23 15:18:30 +02:00
if pgrep "$pgrepplayer" > /dev/null; then
if [ "$1" = "buzzer" ]; then
2020-09-23 15:18:30 +02:00
pkill "$pgrepplayer"
elif [ "$1" = "cron" ]; then
exit 1
fi
else
2020-09-23 15:18:30 +02:00
$playerfull "$(find "$folder" -maxdepth 1 -type f |sort -R |head -n1)" &
fi