RandomVideo/RandomVideo.sh

66 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: Unlicense
configfile="config.json"
cmdjq="$(command -v jq)"
if [ -z "$cmdjq" ]; then
echo "Missing \"jq\"!"
exit 1
fi
cmdgpio="$(command -v gpio)"
if [ -z "$cmdgpio" ]; then
echo "Missing \"gpio\"!"
echo "This is a part of WiringPi-Package."
exit 1
fi
player="$($cmdjq -r ".player" < $configfile)"
if [ -z "$(command -v $player)" ]; then
echo "Missing \"$player\"!"
exit 1
fi
folder="$($cmdjq -r ".RandomVideo | .folder" < $configfile)"
playerparam="$($cmdjq -r ".playerparam" < $configfile)"
pgrepplayer="$($cmdjq -r ".pgrepplayer" < $configfile)"
swupgpio="$($cmdjq -r ".swupgpio" < $configfile)"
playerfull="$(command -v $player) $playerparam"
swupstat="$($cmdgpio read $swupgpio)"
if [ $# -eq 0 ]; then
echo "Parameter fehlt"
exit 1
fi
if [ $# -gt 1 ]; then
echo "Zu viele Parameter"
exit 1
fi
if [ "$swupstat" -eq 1 ]; then
exit 1
fi
if [ "buzzer" != "$1" ] && [ "cron" != "$1" ]; then
echo "Parameter muss \"buzzer\" oder \"cron\" sein"
exit 1
fi
if pgrep "$pgrepplayer" > /dev/null; then
if [ "$1" = "buzzer" ]; then
pkill "$pgrepplayer"
elif [ "$1" = "cron" ]; then
exit 1
fi
else
$playerfull "$(find "$folder" -maxdepth 1 -type f |sort -R |head -n1)" &
fi