Files
raspscreen/manage.sh
DaanSelen a77e59929a
Some checks failed
Cross-Compile Binaries / compile-linux (push) Failing after 4m53s
Cross-Compile Binaries / compile-windows (push) Failing after 8m42s
chore: working
2026-02-04 16:31:47 +01:00

100 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
#
# Utility to manage the userland program called RaspScreen by Systemec B.V.
#
# Where it should live: /opt/raspscreen/bin/manage.sh
#
# Examples:
# ./manage.sh (restart|stop|start) (presentation|video)
#
# systemctl must be reachable from the path of the executing user.
app_name="raspscreen"
# Fallback for display selection
if [[ -z $DISPLAY ]]; then
echo "Triggered exporting display variable fallback..."
export DISPLAY=:0
fi
runtime_id=$(id -u)
if [[ "$runtime_id" -eq 0 ]]; then
echo "Do not run as root. Run as the graphical user."
exit 1
fi
printf "Checking input..."
case "$1" in
restart|stop|start|kill)
printf "Valid command...";;
*)
echo "Invalid command!"
exit 1;;
esac
case "$2" in
presentation|video)
echo "Valid service...";;
*)
echo "Invalid service!"
exit 1;;
esac
if [[ "$1" == "kill" ]]; then
if [[ "$2" == "presentation" ]]; then
/usr/bin/killall libreoffice
exit $?
fi
if [[ "$2" == "video" ]]; then
/usr/bin/killall vlc
exit $?
fi
fi
case "$3" in
--foreground)
if [[ "$2" == "presentation" ]]; then
media_file=$(find /opt/raspscreen/media \( -name "*.pptx" -o -name "*.odp" \))
if [[ -z "$media_file" ]]; then
echo "No compatible media file found. Wrong mode?"
echo "Exiting in 20 seconds..."
sleep 20s
exit 1
else
/usr/bin/libreoffice --impress --show --norestore "$media_file"
fi
fi
if [[ "$2" == "video" ]]; then
media_file=$(find /opt/raspscreen/media \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \))
if [[ -z "$media_file" ]]; then
echo "No compatible media file found. Wrong mode?"
echo "Exiting in 20 seconds..."
sleep 20s
exit 1
else
/usr/bin/vlc --fullscreen --loop --no-video-title --video-on-top --no-qt-fs-controller --qt-continue=0 "$media_file"
fi
fi
echo "Process exited..."
exit 0
;;
*)
echo "Running in task mode...";;
esac
echo "Executing task..."
cmd_result=$(systemctl --user "$1" "$2" 2>&1)
cmd_exit=$?
if [[ "$cmd_exit" -eq 0 ]]; then
echo "Succesfully exited, see:"
if [[ -n "$cmd_result" ]]; then
echo " -> $cmd_result"
fi
else
echo "Something went wrong, see..."
echo " -> $cmd_result"
fi
exit 0