Files
raspscreen/manage.sh

90 lines
2.4 KiB
Bash
Raw Normal View History

#!/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)
2026-02-04 15:05:31 +01:00
#
# systemctl must be reachable from the path of the executing user.
2026-02-04 16:31:47 +01:00
app_name="raspscreen"
runtime_id=$(id -u)
if [[ "$runtime_id" -eq 0 ]]; then
echo "Do not run as root. Run as the graphical user."
2026-02-04 15:05:31 +01:00
exit 1
fi
printf "Checking input..."
case "$1" in
2026-02-05 16:22:18 +01:00
restart|stop|start)
2026-02-04 15:05:31 +01:00
printf "Valid command...";;
*)
echo "Invalid command!"
exit 1;;
esac
case "$2" in
presentation|video)
echo "Valid service...";;
*)
echo "Invalid service!"
exit 1;;
esac
case "$3" in
--foreground)
2026-02-05 16:22:18 +01:00
echo "Gathering uptime data..."
sys_uptime=$(cat /proc/uptime | awk '{print int($1)}')
if [[ "$sys_uptime" -lt 60 ]]; then
echo "Detected a recent restart - giving the operating system some time..."
sleep 10s
fi
2026-02-04 15:05:31 +01:00
if [[ "$2" == "presentation" ]]; then
2026-02-04 16:31:47 +01:00
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
2026-02-05 16:22:18 +01:00
elif [[ "$2" == "video" ]]; then
2026-02-04 16:31:47 +01:00
media_file=$(find /opt/raspscreen/media \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \))
2026-02-04 17:00:23 +01:00
2026-02-04 16:31:47 +01:00
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
2026-02-04 15:05:31 +01:00
fi
2026-02-04 16:31:47 +01:00
echo "Process exited..."
exit 0
;;
2026-02-04 15:05:31 +01:00
*)
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