Files
raspscreen/manage.sh

60 lines
1.5 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.
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
restart|stop|start)
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)
if [[ "$2" == "presentation" ]]; then
/bin/sh -c 'exec /usr/bin/libreoffice --impress --show --norestore $(find /opt/raspscreen/media \( -name "*.pptx" -o -name "*.odp" \))'
fi
if [[ "$2" == "video" ]]; then
/bin/sh -c 'exec /usr/bin/libreoffice --impress --show --norestore $(find /opt/raspscreen/media \( -name "*.pptx" -o -name "*.odp" \))'
fi
*)
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