2020-08-23 01:33:37 +02:00
|
|
|
#!/bin/sh
|
2020-09-23 15:18:30 +02:00
|
|
|
# SPDX-License-Identifier: Unlicense
|
2020-08-23 01:33:37 +02:00
|
|
|
|
2020-09-24 21:52:14 +02:00
|
|
|
configfile="config.json"
|
2020-08-23 01:33:37 +02:00
|
|
|
|
2020-09-26 13:11:22 +02:00
|
|
|
if [ -z "$(command -v jq)" ]; then
|
2020-09-24 10:44:28 +02:00
|
|
|
echo "Missing \"jq\"!"
|
2020-09-24 10:40:46 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-09-26 13:11:22 +02:00
|
|
|
if [ -z "$(command -v gpio)" ]; then
|
2020-09-24 21:52:14 +02:00
|
|
|
echo "Missing \"gpio\"!"
|
|
|
|
echo "This is a part of WiringPi-Package."
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-09-24 10:40:46 +02:00
|
|
|
|
2020-09-26 13:11:22 +02:00
|
|
|
player="$(jq -r ".player" < $configfile)"
|
2020-09-24 21:52:14 +02:00
|
|
|
if [ -z "$(command -v $player)" ]; then
|
|
|
|
echo "Missing \"$player\"!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-08-23 01:33:37 +02:00
|
|
|
if [ $# -eq 0 ]; then
|
2020-09-26 13:11:22 +02:00
|
|
|
echo "Missing parameter!"
|
2020-08-23 01:33:37 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -gt 1 ]; then
|
2020-09-26 13:11:22 +02:00
|
|
|
echo "To much parameters!"
|
2020-08-23 01:33:37 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-09-26 13:20:59 +02:00
|
|
|
if [ "buzzer" != "$1" ] && [ "cron" != "$1" ]; then
|
|
|
|
echo "parameters must be \"buzzer\" or \"cron\"!"
|
2020-09-19 23:33:19 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-09-26 13:20:59 +02:00
|
|
|
swupstat="$(gpio read $swupgpio)"
|
|
|
|
if [ "$swupstat" -eq 1 ]; then
|
2020-08-23 01:33:37 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-09-26 13:20:59 +02:00
|
|
|
folder="$(jq -r ".RandomVideo | .folder" < $configfile)"
|
|
|
|
playerparam="$(jq -r ".playerparam" < $configfile)"
|
|
|
|
pgrepplayer="$(jq -r ".pgrepplayer" < $configfile)"
|
|
|
|
|
|
|
|
swupgpio="$(jq -r ".swupgpio" < $configfile)"
|
|
|
|
|
|
|
|
playerfull="$(command -v $player) $playerparam"
|
|
|
|
|
2020-09-23 15:18:30 +02:00
|
|
|
if pgrep "$pgrepplayer" > /dev/null; then
|
2020-08-23 01:33:37 +02:00
|
|
|
if [ "$1" = "buzzer" ]; then
|
2020-09-23 15:18:30 +02:00
|
|
|
pkill "$pgrepplayer"
|
2020-08-23 01:33:37 +02:00
|
|
|
|
|
|
|
elif [ "$1" = "cron" ]; then
|
2020-08-23 04:08:43 +02:00
|
|
|
exit 1
|
2020-08-23 01:33:37 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
2020-09-23 15:18:30 +02:00
|
|
|
$playerfull "$(find "$folder" -maxdepth 1 -type f |sort -R |head -n1)" &
|
2020-08-23 01:33:37 +02:00
|
|
|
|
|
|
|
fi
|